akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
x = sorted(x, key=lambda x: x[0])
idx = 0
ans = 0
for i in range(n):
    idx += x[i][1]
    if idx >= k:
        ans = x[i][0]
        break
print(ans)


Measured memory_bytes: 29912
n, l = list(map(int, input().split()))
total = 0
for i in range(1, n+1):
    total += l+i-1

m = 1000000000
ans = 0
for i in range(1, n+1):
    a = total-(l+i-1)
    # print(a)
    if abs(total-a) < m:
        m = abs(total-a)
        ans = a

print(ans)


Measured memory_bytes: 61536
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<ll,P>;
using PP = pair<P ,P>;
constexpr ll MOD = 998244353;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

vector<vector<P> > g;
vector<int> ans;

void dfs(int v, int c){
    int nc = 1;
    for(auto e : g[v]){
        int u = e.first;
        int id = e.second;
        if(ans[id] == 0){
            if(nc == c) nc++;
            ans[id] = nc;
            dfs(u, nc);
            nc++;
        }
    }
}

int main(){
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n-1);
    for(int i=0;i<n-1;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(P(b,i));
        g[b].push_back(P(a,i));
    }
    dfs(0,0);
    int ma = 0;
    for(int i=0;i<n-1;i++){
        ma = max(ma, ans[i]);
    }
    cout << ma << endl;
    for(int i=0;i<n-1;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
int main(void){
    // Your code here!
 int i,j,n;
 cin >> n;
 vector<int> a(1000001,1);
 a[0]=0;
 for(i=2;i<=1000000;i++)
 {
  for(j=i;j<=1000000;j+=i)
  a[j]++;
 }
 for(i=1;i<=1000000;i++)
 a[i]+=a[i-1];
 cout << a[n-1];
 return 0;
}

Measured memory_bytes: 7224
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}

fn main() {
    input!{
        n: usize,
        a: [usize; n],
    }
    let mut ans: usize = 1;
    for i in 0..n {
        if a[i] == 0 {
            println!("0");
            return;
        }
    }
    for i in 0..n {
        let dig = ans.to_string().len() + a[i].to_string().len();
//        println!("{}", dig);
        ans = ans * a[i];
        if ans > 1000000000000000000 {
            println!("-1");
            return;
        }
        else if ans < 1000000000000000000 && dig >= 20 {
            println!("-1");
            return;
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 4760
p = 998244353
N = 2*10**5
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % p

def main():
    n, m, k = [int(i) for i in input().split()]
    res = 0
    for tk in range(0, k+1):
        res = (res + m * cmb(n-1, tk, p) * pow(m-1, n-tk-1, p)) % p
    print(res)

if __name__ == '__main__':
    main()



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

#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR_IN(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define IN(x, a, b) ((x) >= (a) && (x) <= (b))

using namespace std;
typedef long long int ll;
/*
N W
vi wi

N 100
W 10000

 */

int N,W;
int w[100],v[100];
ll dp[101][10001];

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

  REP(i, N){
    cin >> v[i] >> w[i];
  }

  REP(i,N){
    REP(j,W+1){
      if(j<w[i]){
        dp[i+1][j] = dp[i][j];
      } else {
        dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
      }
    }
  }

  cout << dp[N][W] << endl;
  return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }else{
        return false;
    }
}

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

    int d, n;
    cin >> d >> n;

    vector<int> t(d);
    rep(i, d){
        cin >> t[i];
    }

    vector<int> c(n);
    vector< vector<bool> > v(d, vector<bool>(n, false));
    rep(i, n){
        int a, b;
        cin >> a >> b >> c[i];
        rep(j, d){
            if(a <= t[j] && t[j] <= b){
                v[j][i] = true;
            }
        }
    }

    int dp[201][200] = {0};
    REP(i, 1, d){
        rep(j, n){
            rep(k, n){
                if(v[i - 1][j] && v[i][k]){
                    chmax(dp[i + 1][k], dp[i][j] + abs(c[j] - c[k]));
                }
            }
        }
    }

    int ans = 0;
    rep(j, n){
        chmax(ans, dp[d][j]);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int k,a,b,c=0,i,j;

    cin>>k>>a>>b;

    for(i=a;i<=b;i+=1)
    {
       // if(a%k==0)
        if(i%k==0)
        {
            c=1;
            break;
        }

        else
            c=0;

      /*  if(c)

           // cout<<"OK\n";
            break;*/



    }

    if(c==1)
        {
            cout<<"OK\n";
            //break;
        }

         else{
            cout<<"NG\n";
        }


    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
#define min(a,b) (a<b?a:b)
struct x{int p,q,r,b;}B[105];
int N,i,j,h[105],r,t;

int gcd(int a,int b)
{
	int c;
	for(;b!=0;)
	{
		c=a%b;a=b;b=c;
	}
	return a;
}

int dfs(int p)
{
	int r,b,i,j,ta,tb,ri,rj,t1,t2;
	if(p==-1)return 1;
	if(h[p]>=0)return h[p];
	r=dfs(B[p].r);
	b=dfs(B[p].b);
	for(i=1,ri=rj=-1;i<=10000000;i++)
	{
		if((r*i*B[p].p)%(b*B[p].q))continue;
		j=(r*i*B[p].p)/(b*B[p].q);
		ta=r*i/B[p].q;
		tb=b*j/B[p].p;
		if(ta&&tb&&ta==tb)
		{
			if(ri==-1||ri*r+rj*b>i*r+j*b)
			{
				ri=i;
				rj=j;
				goto e;
			}
		}
	}
	e:
	if(rj==-1)ri=rj=(r*b)/gcd(r,b);
	return h[p]=r*ri+b*rj;
}

int main()
{
	for(;scanf("%d",&N),N;)
	{
		memset(h,-1,sizeof(h));
		for(i=0;i<N;i++)
		{
			scanf("%d%d%d%d",&B[i].p,&B[i].q,&B[i].r,&B[i].b);
			t=gcd(B[i].p,B[i].q);
			B[i].p/=t;B[i].q/=t;
			B[i].r--;B[i].b--;
		}
		for(i=r=0;i<N;i++)
		{
			t=dfs(i);
			r=r>t?r:t;
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}



void solve(){	
	int a, b;
	cin>>a>>b;
	rep(i,b-a+1,b+a)
	cout << i << " ";
	cout << endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main() {
  int r,D,x0;
  cin >> r >> D >> x0;

  vector<int> x(11);
  x.at(0)=x0;
  
  for(int i=0;i<10;i++){
    x.at(i+1)=r*x.at(i)-D;
    cout << x.at(i+1) << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int x=0,y=0,z=0;
	
	while(1)
	{
		scanf("%d %d",&x,&y);
		
		if(x>y)
		{
			z=x;
			x=y;
			y=z;
			printf("%d %d\n",x,y);
		}
		else if(x==0&&y==0)
		{
			break;
		}
		else 
		{
			printf("%d %d\n",x,y);
		}
      
    
	}
	
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

int main(void)
{
  const int dataNum = 10;

  std::vector<int> vals;
  for (int i = 0; i < dataNum; i++) {
    int newVal;
    std::cin >> newVal;
    vals.push_back(newVal);
  }

  std::sort(vals.begin(), vals.end(), std::greater<int>());

  const int outputDataNum = 3;
  
  for (int i = 0; i < outputDataNum; i++) {
    std::cout << vals[i] << std::endl;
  }

  return 0;
}

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

int main(void){
    int a, b, d, r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = double(a) / double(b);
    cout << d << ' ' << r << ' ';
    cout << fixed << setprecision(5) << f << endl;
}



Measured memory_bytes: 3288
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define prev prev1
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
// std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// int myRand(int R) {
// 	int val=rng() % R;
//       assert(val>=0);
//       return val;
// }
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=3e18;
const int32_t LOG=21;
const int MOD=MOD1;

bool bad[1000005];
bool check[1000005];
int cnt[1000005];
int a[200005];

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      { 
           int n;
           cin>>n;
           rep(i,0,n)
           {
              cin>>a[i];
              cnt[a[i]]++;
           }
           rep(i,0,n)
           {
                 if(check[a[i]])continue;
                 check[a[i]]=true;
                 if(cnt[a[i]]>1)bad[a[i]]=true;
                 int x=a[i];
                 for(int j=2*x;j<=1000001;j+=x)
                 {
                      bad[j]=true;
                 }
           }
           int tot=0;
           rep(i,0,n)
           {
                 if(!bad[a[i]])tot++;
           }
           cout<<tot<<endl;
      }      
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 14956
#include <iostream>
#include <stdlib.h>
#include <stdio.h>


int main() {
    int r = 0, c = 0;
    int r_sum, c_sum, t_sum = 0;
    scanf("%d %d", &r, &c);
    
    // ???????????????????¢????
    int **n;
    n = new int*[r+1];
    for (int i = 0; i < r+1; i++) {
        n[i] = new int[c+1];
    }
    
    for (int i = 0; i < r; i++) {
        // ????????¨???sum????????????
        r_sum = 0;
        for (int j = 0; j < c; j++) {
            std::cin >> n[i][j];
            r_sum += n[i][j];
        }
        n[i][c] = r_sum;
    }
    
    for (int j = 0; j < c; j++) {
        c_sum = 0;
        for (int i = 0; i < r; i++) {
            c_sum += n[i][j];
        }
        n[r][j] = c_sum;
        t_sum += c_sum;
    }
    
    n[r][c] = t_sum;
    
    for (int i = 0; i < r+1; i++) {
        for (int j = 0; j < c+1; j++) {
            if (j == c) {
                printf("%d\n", n[i][j]);
            } else {
                printf("%d ", n[i][j]);
            }
        }
    }
    
    delete [] n;
    return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define ll long long int
#define K 1000000007
#define x first
#define y second
using namespace std;

pair<int, int> a[100];
int main() {
	/*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    */
    int n;cin>>n;
    
    for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y;
    int fal=0;
    for(int i=0;i<n-2;i++)
    {
        int f2=0;
        for(int j=0;j<3;j++)
            if(a[i+j].x!=a[i+j].y){f2=1;break;}
        
        if(f2==0){fal=1;break;}
    }
    if(fal==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
typedef long long ll;

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

int main() {
    int N; cin >> N;
    ll X; cin >> X;
    ll res = 0;
    rep(i, N){
        ll x; cin >> x;
        res = GCD(res, abs(x - X));
    }
    OP(res);
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

    int n = sc.nextInt();

    int[] b = new int[n-1];
    for (int i = 0; i < n-1; i++) {
        b[i] = sc.nextInt();
    }

    int[] a = new int[n];

    a[a.length-1] = b[b.length-1];
    a[0] = b[0];

    for (int i = a.length - 2; i > 0; i--) {
        a[i] = b[i-1] < b[i] ? b[i-1] : b[i];
    }

    System.out.println(IntStream.of(a).sum());
  }
}

Measured memory_bytes: 28756
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N,M;
    cin>>N>>M;
    vi l(M), r(M), x;
    rep(i, M){
        cin >> l[i] >> r[i];
        --l[i];
        x.pb(l[i]);
        x.pb(r[i]);
    }
    sort(all(x));
    x.erase(unique(all(x)), x.end());
    vi v(x.size(), 0);
    rep(i, M){
        int li = lower_bound(all(x), l[i]) - x.begin();
        int ri = lower_bound(all(x), r[i]) - x.begin();
        ++v[li];
        --v[ri];
    }
    
    int counter=0,ans=0;
    rep(i,x.size()-1) {
        counter+=v[i];
        if(counter>=M) ans += x[i+1] - x[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; i++){
    cin >> L.at(i) >> R.at(i);
  }
  int min = *std::min_element(R.begin(), R.end());
  int max = *std::max_element(L.begin(), L.end());
  int count = min- max+1;
  if (count < 0){
    cout << 0 << endl;
  }
  else{
    cout << count << endl;
  }
}   

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

//#define int ll


int a,b,c,d;

signed main(){
    cin>>a>>b>>c>>d;
    
    int x=sqrt((a-c)*(a-c)+(b-d)*(b-d));
    int i=d-b,j=c-a;
    cout<<c-i<<" "<<d+j<<" "<<(c-i)-j<<" "<<(d+j)-i<<" "<<endl;
    
    
    return 0;
}

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

int N;
ll dat[2000000];

void init(int n){
    N=1;
    while(N<n) N*=2;
    for(int i=0;i<2*N;i++) dat[i] = 0;
}
void update(int i,ll x){
    i += N-1;
    dat[i] = max(dat[i],x);
    while(i>0){
        i = (i-1)/2;
        dat[i] = max(dat[i*2+1], dat[i*2+2]);
    }
}
ll query(int a,int b,int k,int l,int r){
    if(r<=a || b<=l) return 0;
    if(a<=l && r<=b) return dat[k];
    else{
        ll vl = query(a,b,k*2+1,l,(l+r)/2);
        ll vr = query(a,b,k*2+2,(l+r)/2,r);
        return max(vl,vr);
    }
}

ll query(int a,int b){
    return query(a,b,0,0,N);
}

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

    ll n;
    cin>>n;
    ll a[n],h[n];
    init(n+1);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        ll ret = query(0,h[i]);
        // cerr << i << " " << ret << endl;
        update(h[i],ret + a[i]);
    }
    ll ans = query(0,n+1);
    cout << ans << endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P;
typedef vector<int> Vi;
int const MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { return a = b; } return false; }

Int dp[1001][1001];

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
    
  int h,w; cin>>h>>w; char g[h][w];
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++)cin>>g[i][j];
  }
  dp[0][1]=1;
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if(g[i][j]=='#')dp[i+1][j+1]=0;
      else dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1])%MOD;
    }
  }
  cout<<dp[h][w]<<'\n';
}

Measured memory_bytes: 9088
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 205;

vector<int> adj[N];
int col[N], last;
vector<int> components[N];
bool vis[N];

void dfs(int u) {
	vis[u] = 1;
	components[last].push_back(u);
	for(auto v : adj[u]) {
		if(vis[v]) continue;
		dfs(v);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			char k;
			cin >> k;
			if(k == '1') adj[i].push_back(j);
		}
	}
	for(int i=0;i<n;i++) {
		if(vis[i]) continue;
		dfs(i);
		last++;
	}
	int ret = 0;
	for(int i=0;i<last;i++) {
		vector<int> &m = components[i];
		int mx = -1;
		for(int start=0;start<m.size();start++) {
			bool fail = false;
			memset(col, 0, sizeof col);
			int now = m[start];
			queue<int> q;
			q.push(now);
			col[now] = 1;
			while(!q.empty()) {
				if(fail) break;
				int u = q.front();
				q.pop();
				for(auto v : adj[u]) {
					if(col[v] && abs(col[v]-col[u])!=1) {
						fail = true;
						break;
					}
					else if(col[v]) continue;
					col[v] = col[u] + 1;
					q.push(v);
				}
			}
			if(fail) continue;
			for(int g=0;g<m.size();g++) {
				mx = max(mx, col[m[g]]);
			}
		}
		if(mx==-1) {
			cout << -1;
			exit(0);
		}
		ret += mx-1;
	}
	cout << ret + 1;
	return 0;
}


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

int main(){
  int n, k, s;  cin >> n >> k >> s;
  rep(i,k)
      cout << s << " ";
  rep(i,n-k)
    if(s == 1e9)
      cout << 1 << " ";
    else
      cout << s+1 << " ";
  return 0;
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int N;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
        }


        public void Solve()
        {
            Scan();
            if (N <= 999)
            {
                Console.WriteLine($"ABC");
            }
            else
            {
                Console.WriteLine($"ABD");
            }
        }


        static void Main() => new Program().Solve();
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
void merge(int *,int,int,int);
void msort(int *,int,int);
int A[500000];
int L[500000];
int R[500000];
int n,count=0;
int main(){
  int i;
  int l,m,r;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  msort(A,0,n);

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
    else printf("\n");
  }
  printf("%d\n",count);
  return 0;
}

void msort(int *A,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    msort(A,left,mid);
    msort(A,mid,right);
    merge(A,left,mid,right);
  }

}
void merge(int *A,int left,int mid,int right){
  int n1,n2;
  int i,j,k;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1]=1000000000;
  R[n2]=1000000000;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else{
      A[k]=R[j];
      j=j+1;
    }
    count++;
  }


}

Measured memory_bytes: 5484
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
const long double epi = 0.0000001;
#define PI 3.141592653589793238
//
//
void solve(){
    long double h, m, hlen, mlen;
    cin>>hlen>>mlen>>h>>m;
    long double hour_angle = (h*60+m)/2.00;
    long double min_angle = (m)*6.00;
    long double diff = min(abs(hour_angle - min_angle), 360.00-abs(hour_angle - min_angle));
    long double ans = hlen*hlen + mlen*mlen - 2*hlen*mlen*cos(diff*PI/180.00);
    // cout<<abs(1.001);
    cout<<sqrt(ans);
}
int main(){ 
        hs;
        ll t;
        t=1;
        cout<<fixed<<setprecision(10);
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 4168
n,k=map(int,raw_input().split())
c=[0]*200
for i in[0]*n:c[ord(raw_input()[0])]+=1
p=a=0
while p<1:
 c.sort();p=k;a+=1
 for i in range(k+1):p-=c[-i]>0;c[-i]-=1
print a-1

Measured memory_bytes: 2692
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i,N){
        cin >> A[i];
        --A[i];
    }
    vector<vector<ll>> to(62, vector<ll>(N));
    REP(i,N) to[0][i] = A[i];
    REP(i,60) REP(j,N) to[i+1][j] = to[i][to[i][j]];
    int cur = 0;
    REP(j,60){
        if((K >> j) & 1){
            cur = to[j][cur];
        }
    }
    cout << cur + 1 << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 102472
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
//assert(q==w) если q!=w --> runtime error
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=3e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};
ll a[maxn];
ll kol[100];
int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n;
    cin>>n;
    ll x=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        for(int j=0;j<=60;j++){
            if(a[i]&(1ll<<j)){
                x+=(1ll<<j)%mod*(i-1-kol[j]);
                x%=mod;
                kol[j]++;
            }
            else{
                x+=(1ll<<j)%mod*kol[j];
                x%=mod;
            }
        }
    }
    cout<<x;
	exit(0);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
    int goukei;
   for (int i = 0; i < N; i++) {
    goukei += vec.at(i);}
  
  int SA, SB, s;
   for (int i = 0; i < N; i++) {
     SA += vec.at(i);
     SB = goukei - SA;
     if(SA > SB){
       int p = SA - SB;
        if(p < s)
          s = p;
       else
         break;
     }
     else
       s = SB - SA;
   }
  cout << s << endl;
}


Measured memory_bytes: 3612
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];

int main() {
  int a,b;
  cin>>a>>b;
  if(a+b>=24){
      cout<<a+b-24<<endl;
  }
  else{
      cout<<a+b<<endl;
  }

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = [int(input())-1 for i in range(N)]

    check = [False] * N
    next = 0
    ok = True
    count = 0
    while True:
        check[next] = True
        next = a[next]
        count += 1
        if next == 1:
            break
        if check[next]:
            ok = False
            break

    if ok:
        print(count)
    else:
        print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7852
// https://atcoder.jp/contests/abc110/tasks/abc110_b

#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  int n, m, x, y, t;
  vector<int> xx, yy;

  cin >> n >> m >> x >> y;

  REP(i, n)
  {
    cin >> t;
    xx.push_back(t);
  }

  REP(i, m)
  {
    cin >> t;
    yy.push_back(t);
  }

  sort(ALL(xx));
  sort(ALL(yy));

  int xxx = max(x, xx.back()),
      yyy = min(y, yy.front());

  string r = x < y && xxx < yyy ? "No War" : "War";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int flag=0,flag1=0;
    int d=0,e=0;
    d=(s[0]-'0')*10+(s[1]-'0');
    e=(s[2]-'0')*10+(s[3]-'0');
    if(d<=12&&d>=1)
    {
        flag=1;
    }
    if(e<=12&&e>=1)
    {
        flag1=1;
    }
    if(flag1==1&&flag==1)
    {
        cout<<"AMBIGUOUS\n";
        return 0;
    }
    if(flag==1)
    {
        cout<<"MMYY"<<endl;
        return 0;
    }
    if(flag1==1)
    {
        cout<<"YYMM\n";
        return 0;
    }
    cout<<"NA\n";
}




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

int main(){
  int N;
  cin >> N;
  int64_t pre;
  cin >> pre;
  bool inc=false;
  bool dec=false;
  int64_t A;
  int ans=0;
  for(int i=1;i<N;i++){
    cin >> A;
    if(A>pre){
      if(dec){
        ans++;
        dec=false;
      }else{
        inc=true;
      }
    }else if(A<pre){
      if(inc){
        ans++;
        inc=false;
      }else{
        dec=true;
      }
    }
    pre=A;
  }
  ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/******* all required header files *******/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

/*****All definitions*******/
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define mp make_pair
#define ll long long int
#define pb push_back
#define F first
#define S second
/***************************/

int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

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

	int n;
	cin>>n;
	vector<int> v(n);
	set<int> s ;
	for(int i  = 0; i < n; i++)
    {
	    cin>>v[i];
	    int a = v[i];
	    s.insert(a);
	}
	if(s.size() == n)
	    cout<<"YES";
	else cout<<"NO";
	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define mod 998244353

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    set<ll> s;
    vector<pair<ll,ll>> v;
    for(ll i=0;i<k;i++)
    {
    	ll x1,x2;
    	cin>>x1>>x2;
    	v.push_back(make_pair(x1,x2));
    }
    ll pr[n+1]={0};
    pr[0]=0;
    pr[1]=1;
    ll dp[n+1]={0};
    dp[0]=0;
    dp[1]=1;
    for(ll i=2;i<=n;i++)
    {
    	for(auto u:v)
    	{
    		if(u.first<i)
    		{
    		
    	    dp[i]=(dp[i]%mod+pr[i-u.first]%mod)%mod;
    		ll v=min(u.second+1,i);
    		//cout<<v<<endl;
    		dp[i]=(dp[i]%mod-pr[i-v]%mod)%mod;
    		if(dp[i]<0)
    		dp[i]=dp[i]+mod;
    		}
    	}
    	pr[i]=(pr[i-1]%mod+dp[i]%mod)%mod;
    	//cout<<dp[i]<<endl;
    }
    cout<<dp[n]%mod<<endl;
	return 0;
}

Measured memory_bytes: 6732
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SP << " " <<
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int ans = n * (n - 1) / 2+ m * (m - 1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;

int main(){
    int a;
    cin >> a;
    string s; cin >> s;
    if(a >= 3200){
        cout << s;
    }
    else{
        cout << "red";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
static const int INF = 0x3f3f3f3f;
static const long long int INFL = 0x3f3f3f3f3f3f3f3fLL;
const long long int MOD = 1e9+7;
const long long int  mod = 998244353;


int main()
{
    int n;
    cin>>n;
    vector<long long int> A;
    long long int sum  = 0;
    long long int ans = 0;
    for(int i=0;i<n;++i) {
        long long int a = 0;
        cin>>a;
        ans = ans + (a*sum)%MOD;
        ans = ans%MOD;
        sum += a;
        sum  %= MOD;
    }
    cout<<ans<<endl;
    return 0;
}


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

const int N = 200000 + 5, mod = 1e9 + 7;

int fpow (int base, int v) {
    int tot = 1;
    for (; v; v >>= 1, base = 1LL * base * base % mod) if (v & 1) tot = 1LL * tot * base % mod;
    return tot;
}

vector<int> G[N];
int n, dp[N], sz[N], fac[N], ifac[N], ans[N];

void dfs (int u, int v) {
    dp[u] = 1, sz[u] = 1;
    for (int i = 0; i < (signed)G[u].size(); ++i) if (G[u][i] != v) {
        dfs (G[u][i], u);
        sz[u] += sz[G[u][i]];
        dp[u] = 1LL * dp[u] * dp[G[u][i]] % mod * ifac[sz[G[u][i]]] % mod;
    }
    dp[u] = 1LL * dp[u] * fac[sz[u] - 1] % mod;
}

void dfs2 (int u, int v) {
    if (u != 1)
        ans[u] = 1LL * dp[u] * ifac[sz[u] - 1] % mod * fac[n - 1] % mod * v % mod * ifac[n - sz[u]] % mod;
    int tmp = 1LL * dp[u] * ifac[sz[u] - 1] % mod * v % mod * ifac[n - sz[u]] % mod;
    for (int i = 0; i < (signed)G[u].size(); ++i) if (sz[G[u][i]] < sz[u]) {
        dfs2 (G[u][i], 1LL * tmp * fac[n - sz[G[u][i]] - 1] % mod * fpow (dp[G[u][i]], mod - 2) % mod * fac[sz[G[u][i]]] % mod);
    }
}

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

    fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % mod;
    ifac[n] = fpow (fac[n], mod - 2);
    for (int i = n - 1; i >= 0; --i) ifac[i] = 1LL * ifac[i + 1] * (i + 1) % mod;

    for (int i = 1; i < n; ++i) {
        int a, b; scanf("%d%d", &a, &b);
        G[a].push_back (b), G[b].push_back (a);
    }
    dfs (1, 0);
    ans[1] = dp[1];
    dfs2 (1, 1);
    for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 17780
n=gets.to_i
tt,aa=1,1
tg,ag=1,1
n.times do
  t,a=gets.split.map(&:to_i)
  tg=[t,tt].max
  tg=tg+(t-tg%t)%t
  ag=[a,aa].max
  ag=ag+(a-ag%a)%a
  if tg/t>ag/a
    tt=tg
    aa=tg/t*a
  else
    aa=ag
    tt=ag/a*t
  end
end
puts tt+aa


Measured memory_bytes: 14388
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	ll l,r;cin>>l>>r;
	int res=1e9;
	for(int i=l;i<=l+2019&&i<=r;i++){
		for(int j=i+1;j<=l+2019&&j<=r;j++)
			res=min(res,((i%2019)*(j%2019)%2019));
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
-- Math Functions - Distance

import Control.Applicative
import Text.Printf

main :: IO ()
main = do
  [x1, y1, x2, y2] <- map read . words <$> getLine
  let d = sqrt ((x1 - x2)^2 + (y1 - y2)^2) :: Double
  printf "%f\n" d



Measured memory_bytes: 4084
#include<iostream>
enum{N=100000,M=100000007};long long d[N+1][2];int t,i,j,l[2]={3,5};main(){for(;t<2;t++){for(d[1][t]=i=1;i++<l[t];)d[i][t]=d[i-1][t]*2;for(i=l[t];i++<N;)for(d[i][t]=1,j=0;j++<l[t];)d[i][t]=(d[i][t]+d[i-j][t])%M;}for(std::string s;std::cin>>s,s!="#";printf("%d\n",t))for(s+=(t=j=i=1);i<s.size();i++)s[i-1]-s[i]?(t=t*d[j][s[i-1]-56&&s[i-1]-48]%M),j=1:j++;}

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

int main()
{
    int h1, h2, k1, k2, a, b, c, d;

    cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;

    int sum1 = h1 * a + h2 * b + h1 / 10 * c + h2 / 20 * d;
    int sum2 = k1 * a + k2 * b + k1 / 10 * c + k2 / 20 * d;
    if( sum1 > sum2 )
        cout << "hiroshi" << endl;
    else if( sum1 < sum2 )
        cout << "kenjiro" << endl;
    else
        cout << "even" << endl;

    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, k;
    cin >> n >> k;
    if(k == 1) cout << 0 << endl;
    else cout << n - k << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll MAXN = 4e5 + 3;
namespace COMM {
    ll fac[MAXN], inv[MAXN];
    ll QPow(ll x, ll n) {
        ll ret = 1; 
        ll tmp = x % MOD;
        while(n) {
            if(n&1) ret = (ret * tmp) % MOD;
            tmp = tmp * tmp % MOD;
            n >>= 1;
        }
        return ret;
    }
    void init() {
        fac[0] = 1;
        for (int i = 1; i <MAXN; i++) 
            fac[i] = fac[i-1] * i % MOD;
        inv[MAXN-1] = QPow(fac[MAXN-1], MOD-2);
        for (int i = MAXN-2; i >= 0; i--) 
            inv[i] = inv[i+1] * (i+1) % MOD;
    }
    ll C(ll a, ll b) {
        if(b>a) return 0;
        if(b == 0) return 1;
        return fac[a] * inv[b] % MOD * inv[a-b] % MOD;
    }
}
int main() {
    COMM::init();
    ll n, k; scanf("%lld%lld", &n, &k);
    k = std::min(n-1, k);
    ll res = 0;
    for (int i = 0; i <= k; i++) {
        res = (res + COMM::C(n, i) * COMM::C(n-1, n-i-1) % MOD) % MOD;
    }
    printf("%lld\n", res);
}

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  int n = in();
  int ans = 2 * n;
  string s, t;
  cin >> s >> t;
  int counter = 0;
  REPS(i,1,n+1) {
    if(s.substr(n-i,i) == t.substr(0, i)) counter = i;
  }
  cout << ans - counter;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<' '<<
#define ___ <<' '
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define int long long

struct IoSetup {IoSetup() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout <<fixed<<setprecision(12);
    cerr <<fixed<<setprecision(12);
}}IoSetup;

using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,1,0,-1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a<b?a=b,true:false);}
template<class T>bool chmin(T &a, const T &b){return(a>b?a=b,true:false);}
inline int qp(int a,ll b,int mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}



signed main() {

    int x;

    cin >> x;

    cout << x/500*1000 + x%500/5*5 << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, ll> P;
const int mod=1e9+7;
map<P,ll> MAP;
ll f(ll T1, ll T2) {
  if(MAP.count(P(T1,T2)))return MAP[P(T1,T2)];
  if(T1<0||T2<0)return 0;
  if(T1==0&&T2==0)return 1;
  return MAP[P(T1,T2)]=(f(T1/2,T2/2)+(T1>=2?f((T1-2)/2,T2/2):0)+(T1>=1&&T2>=1?f((T1-1)/2,(T2-1)/2):0))%mod;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;cin>>N;
  cout<<f(N,N)<<endl;
}

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

int main()
{
  int k, n;
  int a[200100];
  cin >> k >> n;

  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  int mx = a[0] + (k - a[n - 1]);
  for (int i = 1; i < n; i++)
  {
    mx = max(mx, a[i] - a[i - 1]);
  }
  cout << k - mx << endl;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d)
    cout<<"Yes"<<endl;
  else if(abs(a-b)<=d&&abs(b-c)<=d)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;



  return 0;
}


Measured memory_bytes: 256