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

#define REP(i,n) for(long long 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)

using ll = long long;
#define INF 1e9

ll N, M;
int main(){
  cin >> N >> M;
  ll ans = 1;
  for(ll i = 1; i*i <= M; i++){
    if(M%i == 0){
      if(i*N <= M){
        ans = max(ans, i);
      }
      if(M/i*N <= M){
        ans = max(ans, M/i);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    ll n,d;cin>>n>>d;

    ll ans=0;
    REP(i,n){
        ll x,y;cin>>x>>y;
        if (pow(x,2) + pow(y,2) <= pow(d,2)) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int max1=0,a[3][101],n;
void fun(int i,int j,int s)
{
	if(i>2||j>n)
	{
		return;
	}
	s+=a[i][j];
	if(i==2&&j==n)
	{
		if(s>max1)
		{
			max1=s;
		}
		return;
	}
	fun(i+1,j,s);
	fun(i,j+1,s);
}
int main()
{
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=2;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	fun(1,1,0);
	printf("%d",max1);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static const long long MOD_NUM = 1000000007LL;

static void B_task();

int main()
{
	B_task();
	fflush(stdout);
	return 0;
}

static void B_task()
{
	int N;
	get1int(N);

	char S[101] = { 0 };
	char T[101] = { 0 };

	getstring(S);
	getstring(T);

	for (int i = 0; i < N; i++) {
		printf("%c%c", S[i], T[i]);
	}
	putchar('\n');
}


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

int main() {
  int n, q;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  cin >> q;
  int T[q];
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }
  int total = 0;
  for (int j = 0; j < q; j++) {
    int left = 0;
    int right = n;
    while (left < right) {
      int mid = (left + right) / 2;
      if (A[mid] == T[j]) {
        total++;
        break;
      } else if (A[mid] > T[j]) {
        right = mid;
      } else {
        left = mid + 1;
      }
    }
  }
  cout << total << endl;
  return 0;
}



Measured memory_bytes: 3644
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from math import ceil, floor, pi
import bisect
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]

def main():
    r = int(input())
    print(2 * pi * r)

if __name__ == '__main__':
    main()
 


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

struct SegTree {
  int size;
  vector<ll> pos;
  SegTree(ll N) { size = 1; while(size<N) size<<=1; pos.resize(2*size,0); }
  ll operator[](const ll &x) const { return pos[x+size]; }

  void build() { per(i,size) operate(i); }
  void set(ll x, const ll v) { pos[x+size] = v; }
  void update(ll x, const ll v) { set(x,v); x+=size; while (x>>=1) operate(x); }
  ll query(ll a, ll b) {
    ll L = 0, R = 0;
    for (a+=size, b+=size; a<b; a>>=1, b>>=1) {
      if (a&1) { L = q(L,pos[a]); a++; }
      if (b&1) { b--; R = q(R,pos[b]); }
    }
    return q(L,R);
  }
  void operate(ll i) { pos[i] = max(pos[i*2],pos[i*2+1]); }
  ll q(ll x, ll y) { return max(x,y); }
};

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

struct flower { ll h, a; };

int main() {
  int N; cin >> N;
  flower f[N];
  rep(i,N) { ll h; cin >> h; h--; f[i].h = h; }
  rep(i,N) { ll a; cin >> a; f[i].a = a; }

  SegTree st(N);
  rep(i,N) st.update(f[i].h,st.query(0,f[i].h)+f[i].a);

  // rep(i,N) cout << st[i] << " "; cout << endl;
  ll result = st.query(0,N);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <tuple>
#include <bitset>

using namespace std;
int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (auto i = 3; i <= N; i+=2) {
        int c = 0;
        for(auto j = 1; j <= N; j+=2) {
            if (i % j == 0) {
                ++c;
            }
        }
        if (c == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s, t, u string
	var a, b int
	fmt.Scanf("%s %s", &s, &t)
	fmt.Scanf("%d %d", &a, &b)
	fmt.Scanf("%s", &u)

	if u == s {
		a -= 1
	}
	if u == t {
		b -= 1
	}

	fmt.Printf("%d %d", a, b)
}


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

class Program
{
    static void Main(string[] args)
    {
        var sol = new Solve();
        sol.Exec();
    }
}

class Solve
{
    public void Exec()
    {
        var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(CombCount(l[0], 2)+CombCount(l[1], 2));
    }

    public static long CombCount(int n, int m)
    {
        if (m == 0) return 1;
        if (n == 0) return 0;
        return (n * CombCount(n - 1, m - 1) / m);
    }
}


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

#define int long long
#define pii pair<int, int>
#define pb push_back

signed main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //     freopen("error.txt", "w", stderr);
    // #endif
    string a,b;
    cin >> a >> b;
    int T, N;
    cin >> T >> N;
    string x;
    cin >> x;
    if(x == a){
        T--;
    }
    else{
        N--;
    }
    cout << T << " " << N << endl;

    return 0;
}   

Measured memory_bytes: 256
import java.util.*;
 
class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a,b;
a =sc.nextInt();
b =sc.nextInt();
 
if(a == b) System.out.println("a == b");
else if(a>b) System.out.println("a > b");
else System.out.println("a < b");
}
}


Measured memory_bytes: 26100
#define inf 10000000000
#include <stdio.h>

/*int main(void){
    int n,T,sum;
    int t[200000];
    int i;
    int base,crnt,prev;
    scanf("%d %d",&n,&T);
    for(i=0;i<n;i++){
        //t[i]はi番目の人がボタンを押すタイミング
        scanf("%d",&t[i]);
    }
    base=0;
    crnt=0;
    while(1){
        int prev=base;
        //隣接する配列の差がTよりも大きくなるまで
    while((t[crnt]-t[prev]<T)){
        if(crnt==n-1){
            sum+=(t[crnt]-t[base])+T;
            printf("%d\n",sum);
            return 0;
        }
        //最初はcrntのみ
        if(crnt==prev){
            crnt++;
        }else{
        crnt++;
            prev++;
        }
        
    }
        sum+=(t[prev]-t[base])+T;
        base=crnt;
        prev=crnt;
    }
    printf("%d\n",sum);
}
*/
int min(long a,long b){
    if(a<b)return a;
    else return b;
}
int main(void){
    long n,T,sum=0;
    long t[200001];
    int i;
    int base,crnt,prev;
    scanf("%ld %ld",&n,&T);
    for(i=0;i<n;i++){
        //t[i]はi番目の人がボタンを押すタイミング
        scanf("%ld",&t[i]);
    }
    t[n]=inf;
    for(i=0;i<n;i++){
        sum+=min(t[i+1]-t[i],T);
    }
    printf("%ld\n",sum);
}


Measured memory_bytes: 1664
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int a=0,b=0;
	int i;
	for(i=0;i<4;i++){
		a+=in();
	}
	for(i=0;i<4;i++){
		b+=in();
	}
	cout<<max(a,b)<<endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
  int N, W; cin >> N >> W;
  int w[1000], v[1000];
  vector<long long> a[4];
  for(int i = 0; i < N; ++i) {
    cin >> w[i] >> v[i];
    a[w[i] - w[0]].push_back(v[i]);
  }
  for(int i = 0; i < 4; ++i) {
    sort(a[i].begin(), a[i].end());
    reverse(a[i].begin(), a[i].end());
    for(int j = 1; j < a[i].size(); ++j) a[i][j] += a[i][j-1];
  }
  long long maxN = 0LL;
  for(int i = 0; i <= a[0].size(); ++i) {
    for(int j = 0; j <= a[1].size(); ++j) {
      for(int k = 0; k <= a[2].size(); ++k) {
        for(int l = 0; l <= a[3].size(); ++l) {
          long long p = 1LL * (w[0] + 0LL) * i + 1LL * (w[0] + 1LL) * j+ 1LL * (w[0] + 2LL)*k + 1LL * (w[0] + 3LL)*l;
          if(p > W) continue;
          long long cnt = 0;
          if(i >= 1) cnt += a[0][i-1];
          if(j >= 1) cnt += a[1][j-1];
          if(k >= 1) cnt += a[2][k-1];
          if(l >= 1) cnt += a[3][l-1];
          maxN = max(maxN, cnt);
        }
      }
    }
  }
  cout << maxN << endl;
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int main() {
  int N;
  cin >> N;
  vi a(N);
  rep(i, N) cin >> a[i];

  int res = 0;
  rep(i, N) {
    while (i + 1 < N && a[i] == a[i + 1]) i++;

    if (i + 1 < N && a[i] <= a[i + 1]) {
      while (i + 1 < N && a[i] <= a[i + 1]) i++;
    } else if (i + 1 < N && a[i] >= a[i + 1]) {
      while (i + 1 < N && a[i] >= a[i + 1]) i++;
    }

    res++;
  }

  cout << res << endl;
}

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

using namespace std;


void solve() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long g = __gcd(c, d);
    long long l = c*d/g;
    auto f = [&](long long x){
        return x - (x/c + x/d - x/l);
    };
    cout << f(b) - f(a-1);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){
    int n,m;
    cin >> n >> m;
    if(n==m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;

void solve(){
	int N;
	cin>>N;
	vi x(101);
	int maxa=0;
	rep(i,0,N){
		int temp;
		cin>>temp;
		x[temp]++;
		maxa=max(maxa,temp);
	}
	for(int i=maxa;i>maxa/2;i--){
		if(x[i]<2){
			cout<<"Impossible";
			return;
		}
		x[i]-=2;
	}
	if(maxa%2==0 && x[maxa/2]<1){
		cout<<"Impossible";
		return;
	}
	else if(maxa%2==0)x[maxa/2]--;
	rep(i,1,(maxa+1)/2+1){
		if(x[i]){
			cout<<"Impossible";
			return;
		}
	}
	cout<<"Possible";
	return;
}

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

Measured memory_bytes: 384
S = input()
ls = list(S)
ans = 0
for i in range(len(ls)):
    cnt = 0
    for j in range(i,len(ls)):
        if S[j] in ['A','T','C','G']:
            cnt += 1
            if j == len(ls) - 1:
                ans = max(ans,cnt)
        else:
            ans = max(ans,cnt)
            break
print(ans)

Measured memory_bytes: 3064
h,n = map(int,input().split())

ab_input = [list(map(int,input().split())) for i in range(n)]

max_d = max(a for a,b in ab_input)

dp =[0]*(h+max_d)
for i in range(1,h+max_d):
    dp[i]=min(dp[i-a]+b for a,b in ab_input)
print(dp[h])


Measured memory_bytes: 74616
n,k=map(int,input().split())
s=input()
s_list=list(s)
for i in range(n):
    if i==k-1:
        if s_list[i]=='A':
            s_list[i]='a'
        elif s_list[i]=='B':
            s_list[i]='b'
        else:
            s_list[i]='c'
print("".join(s_list))


Measured memory_bytes: 3060
n = gets.to_i
l = gets.split.map(&:to_i)

if n < 3
  puts 0
  exit
end

cnt = 0
for i in 0..(n-3)
  for j in (i+1)..(n-2)
    for k in (j+1)..(n-1)
      ls = [l[i],l[j],l[k]]
      ls.sort!
      if ls[0]+ls[1] > ls[2] && ls[0] != ls[1] && ls[1] != ls[2]
        cnt += 1
      end
    end
  end
end
puts cnt

Measured memory_bytes: 14388
#include<stdio.h>
int main()
{
    int x,k=1,i,sum=0;

    scanf("%d",&x);

    int c[x];

    for(i=0;i<x;i++){

        scanf("%d",&c[i]);
    }
    for(i=0;i<x;i++,k++)
    {
       if(c[i]!=k) sum++;
    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;
}


Measured memory_bytes: 1636
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
 	ll n;cin>>n;
 	vector<ll> v(n),p(n);
 	rep(i,0,n)
 	{
	 cin>>v[i];
	 p[i]=v[i];
    }
    sort(p.begin(),p.end());
 	ll mx=*max_element(v.begin(),v.end());
 	rep(i,0,n)
 	{
 	  if(v[i]!=mx) cout<<mx<<endl;
	   else
	   cout<<p[n-2]<<endl;	
	 }
 	
	
	
	
	
	
 return 0;
}

Measured memory_bytes: 4736
#!/usr/bin/env python
"""M-SOLUTIONS プロコンオープン 2020: B - Magic 2
https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_b
"""

import itertools


def is_success(cards):
    return cards[0] < cards[1] < cards[2]


def magic(A, B, C, K):
    for n in range(1, K + 1):
        # print('===={}'.format(n))
        for c in itertools.combinations([0, 1, 2] * n, n):
            cards = [A, B, C]
            for i in range(n):
                # print('i:{}, c:{}'.format(i, c[i]))
                cards[c[i]] = cards[c[i]] * 2
            # print(cards)
            if is_success(cards):
                return True
    return False


def main():
    A, B, C = list(map(int, input().split()))
    K = int(input())
    # A, B, C = [7, 4, 2]
    # K = 3

    if magic(A, B, C, K):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 8988
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		StringBuilder ret = new StringBuilder();
		while (true) {
			n = scanner.nextInt();
			int m = scanner.nextInt();
			int s = scanner.nextInt();
			int g1 = scanner.nextInt();
			int g2 = scanner.nextInt();
			if ((n | m | s | g1 | g2) == 0)
				break;
			s--;
			g1--;
			g2--;
			int[][] smap = new int[n][n];
			int[][] gmap = new int[n][n];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++) {
					smap[i][j] = gmap[i][j] = i == j ? 0 : INF;

				}

			while (m-- > 0) {
				int b1 = scanner.nextInt() - 1;
				int b2 = scanner.nextInt() - 1;
				int c = scanner.nextInt();
				smap[b1][b2] = gmap[b2][b1] = c;
			}
			int[] acost = slove(s, smap);
			int[] bcost = slove(g1, gmap);
			int[] ccost = slove(g2, gmap);

			int ans = INF;
			for (int i = 0; i < n; i++)
				ans = Math.min(ans, acost[i] + bcost[i] + ccost[i]);
			ret.append(ans).append('\n');
		}
		System.out.print(ret);
	}

	private int[] slove(int s, int[][] map) {
		PriorityQueue<Pair> pq = new PriorityQueue<Main.Pair>();
		pq.offer(new Pair(s, 0));
		int[] dp = new int[n];
		Arrays.fill(dp, INF);
		dp[s] = 0;
		while (!pq.isEmpty()) {
			Pair p = pq.poll();
			if (dp[p.d] < p.cost)
				continue;
			for (int i = 0; i < n; i++) {
				int ncost = p.cost + map[p.d][i];
				if (dp[i] <= ncost)
					continue;
				dp[i] = ncost;
				pq.offer(new Pair(i, ncost));
			}
		}
		return dp;
	}

	int INF = 1 << 29;
	int n;

	class Pair implements Comparable<Pair> {
		int d, cost;

		public Pair(int d, int cost) {
			super();
			this.d = d;
			this.cost = cost;
		}

		@Override
		public String toString() {
			return "Pair [d=" + d + ", cost=" + cost + "]";
		}

		@Override
		public int compareTo(Pair o) {
			return cost - o.cost;
		}

	}
}

Measured memory_bytes: 63300
#include <stdio.h>
#include <ctype.h>


int main(void) {
	char str;
	static int cnt[26];
	int ptr;

	while (scanf("%c", &str) != EOF) {

		if (isalpha(str)) {
			if (isupper(str)) ptr = str - 'A';
			else ptr = str - 'a';
			cnt[ptr]++;
		}

	}

	for (int i = 0; i < 26; i++) {
		printf("%c : %d\n", 'a' + i, cnt[i]);
	}
	
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    int n;
    cin >> n;
    ll sum1 = 0, sum2 = 0;
    ll ans1 = 0, ans2 = 0;
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        sum1 += a;
        sum2 += a;
        if(i % 2){
            if(sum1 >= 0){
                ans1 += sum1 + 1;
                sum1 = -1;
            }
            if(sum2 <= 0){
                ans2 += llabs(sum2) + 1;
                sum2 = 1;
            }
        }else{
            if(sum1 <= 0){
                ans1 += llabs(sum1) + 1;
                sum1 = 1;
            }
            if(sum2 >= 0){
                ans2 += sum2 + 1;
                sum2 = -1;
            }
        }
    }
    cout << min(ans1, ans2) << endl;
}


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

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




Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define fo(i,k,n) for(i=k;i<=n;i++)
#define endl '\n'
ll dp[101][100001];
//memoisation
ll knapsnack(ll* w,ll* v,ll n,ll mw){
	if(dp[n][mw]>-1) return dp[n][mw];
	if(n==0) return 0;//no item left
	if(mw==0) return 0;//no more capacity
	ll op1 = knapsnack(w,v,n-1,mw);
	ll op2 = LLONG_MIN;
	if(w[n-1]<=mw) op2 = v[n-1]+knapsnack(w,v,n-1,mw-w[n-1]);
	return dp[n][mw]=max(op1,op2);
}
//tabulation
ll knapsnacki(ll* w,ll* v,ll n,ll mw){
	ll i,j;
	fo(i,0,mw) dp[0][i]=0;
	fo(i,0,n) dp[i][0]=0;
	fo(i,1,n){
		fo(j,1,mw){
			dp[i][j] = dp[i-1][j];
			if(w[i-1]<=j) dp[i][j] = max(dp[i][j],v[i-1]+dp[i-1][j-w[i-1]]);
		}
	}
	return dp[n][mw];
}
//tabulation memory optimised
ll knapsnacki2(ll* w,ll* v,ll n,ll mw){
	ll i,j;
	ll dp2[2][mw+1];
	fo(i,0,mw) dp2[0][i]=0;
	dp2[1][0]=0;
	ll idx=1;
	fo(i,1,n){
		fo(j,1,mw){
			dp2[idx][j] = dp2[idx^1][j];
			if(w[i-1]<=j) dp2[idx][j] = max(dp2[idx][j],v[i-1]+dp2[idx^1][j-w[i-1]]);
		}
		idx^=1;
	}
	return dp2[idx^1][mw];
}
void solve(){
	ll i,j,n,mw;
	cin>>n>>mw;
	ll* w = new ll[n];
	ll* v = new ll[n];
	fo(i,0,n-1){
		cin>>w[i]>>v[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<knapsnacki2(w,v,n,mw)<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll t;
	t=1;//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 80768
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int > x(n,0);
  vector<int > xc(n,0);
  REP(i,n){cin >> x[i];
    xc[i] = x[i];
  }
  sort(all(xc));
  int m = n/2;
  int b1 = xc[m];
  int b2 = xc[m - 1];
  REP(i, n){
    if(x[i] <= b2){
      cout << b1 << endl;
    }else{
      cout << b2 << endl;
    }
  }
}


Measured memory_bytes: 3712
h,w=map(int,input().split())
masu=[list(input()) for a in range(h)]
masu2=[[0 for a in range(w)] for a in range(h)]
for i in range(h):
    for j in range(w):
        a=0
        if i>0:
            a+=masu[i-1][max(0,j-1):min(w,j+2)].count("#")
        a+=masu[i][max(0,j-1):min(w,j+2)].count("#")
        if i<h-1:
            a+=masu[i+1][max(0,j-1):min(w,j+2)].count("#")
        if masu[i][j]=="#":
            masu2[i][j]="#"
        else:
            masu2[i][j]=str(a)
for a in masu2:
    print("".join(a))

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

const int max_n = 2e5;

int main()
{
    int n, a[max_n], b[max_n];
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }

    int sum = 0;
    for (int i = n; i >= 1; --i)
    {
        long long res = 0;
        long long k = i * 2;
        while (k <= n)
        {
            res += b[k - 1];
            res %= 2;
            k += i;
        }

        if (res != a[i - 1])
        {
            b[i - 1] = 1;
            ++sum;
        }
        else
        {
            b[i - 1] = 0;
        }
    }

    cout << sum << endl;
    for (int i = 0; i < n; ++i)
    {
        if (b[i] == 1)
        {
            cout << i + 1 << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,d,a,ans=0,cur=0;
	cin>>n>>d>>a;
	vl b(n+1);
	vector<pll> xh(n);
	rep(i,n)cin>>xh[i].fs>>xh[i].sc;
	sort(all(xh));
	rep(i,n){
		cur-=b[i];
		ll rem=xh[i].sc;
		rem-=cur*a;
		ll cnt=max(0ll,(rem+a-1)/a);
		cur+=cnt;
		b[upper_bound(all(xh),pll(xh[i].fs+2*d,0ll),[](pll a,pll b){
			return a.fs < b.fs;
		})-xh.begin()]+=cnt;
		ans+=cnt;
		//puta(ans);
	}
	//puta(b);
	puta(ans);
}


Measured memory_bytes: 4992
def cycle_getter(N, start):
    """
    :param N: 移動回数
    :param start:　初期条件
    :return front: cycleまでの要素のリスト
            cycle: cycle内の要素のリスト
            end: cycle後の余った部分の要素のリスト
            cnt: cycle回数
    """
    p = start
    front, cycle, end = [], [], []
    cnt = 0
    visit = {p:0}
    L, R = N, -1
    P = [p]
    for i in range(1,N):
        p = lift(p)
        if p in visit:
            """
            (L, R) = (サイクルに入るまでに移動した回数, サイクルの終端に着くまでに移動した回数)
            [6,2,3,4,0,1,2] ⇒ (L, R) = (1, 6)
            """
            L, R = visit[p], i
            period = R-L
            break
        visit[p] = i
        P.append(p)
    front = P[:L]
    if L != N:
        cycle, end = P[L:R], P[L:L+(N-L)%period]
        cnt = (N-L)//period
    return front, cycle, end, cnt

################################################################################


import sys
input = sys.stdin.readline

def lift(x): return pow(x,2,M)

N, X, M = map(int, input().split())
front, cycle, end, cnt = cycle_getter(N,X)
# print(front, cycle, end, cnt)
print(sum(front)+sum(cycle)*cnt+sum(end))

Measured memory_bytes: 77860
N = gets.strip.to_i
p = gets.strip.split.map(&:to_i)



ans=0
(2..N-1).reverse_each do |i|
    p0=p[i-2]
    p1=p[i-1]
    p2=p[i]
    
    if p0<p1 && p1<p2 || p0>p1 && p1>p2
        ans+=1
    end

end

puts ans


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

int main() {
  int n,y;
  cin >> n >> y;
  for(int i=0; i<=n; i++){
    for(int j=0; j<=n-i; j++){
      int sum=0;
      sum+=10000*i;
      sum+=5000*j;
      int k=n-i-j;
      sum+=1000*k;
      if(sum==y){
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
      if(i== n){
        cout << -1 << " " << -1 << " " << -1 << endl;
      }
        
      
    }
  }
        
  
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  ll n; std::cin >> n;
  ll sub = 1;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) sub = i;
  }
  std::cout << sub - 1 + n / sub - 1 << "\n";
}


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

int main(){
	int n, p;
	bool route[101][101];
	
	for(int i=0; i<=100; ++i)
	for(int j=0; j<=100; ++j)
	route[i][j]=false;
	
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		int r, k;
		scanf(" %d %d", &r, &k);
		for(int j=0; j<k; ++j){
			int t;
			scanf(" %d", &t);
			route[r][t]=true;
		}
	}
	
	scanf(" %d", &p);
	for(int i=0; i<p; ++i){
		int cost[101];
		for(int j=0; j<=100; ++j) cost[j]=20000;
		
		int s, d, v;
		scanf(" %d %d %d", &s, &d, &v);
		
		//bfs
		queue<int> que;
		cost[s]=1;
		que.push(s);
		while( !que.empty() ){
			int v=que.front();
			que.pop();
			for(int j=1; j<=n; ++j){
				if(route[v][j] && cost[j] > cost[v]+1){
					cost[j]=cost[v]+1;
					que.push(j);	
				}
			}	
		}
		
		if(cost[d] <= v) printf("%d\n", cost[d]);
		else printf("NA\n");
	}	
	
	
}

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

int main(void) {
    int n;
    cin >> n;
    vector< int > a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int m                        = a[n - 1];
    vector< int >::iterator iter = upper_bound(a.begin(), a.end(), m / 2);
    int r                        = *iter;
    for (int i = 0; i < 2; ++i) {
        --iter;
        if (abs((*iter) * 2 - m) <= abs(r * 2 - m)) {
            r = *iter;
        }
    }
    printf("%d %d\n", m, r);

    return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(100000)

N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
    a, b = (int(i) for i in input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

prev = [-1]*N
def DFS(start):
    res = 0
    for u in G[start]:
        if u != prev[start]:
            prev[u] = start
            res += DFS(u)
    return res+1

DFS(0)
start = N-1
path = [N-1]
while True:
    path.append(prev[start])
    start = prev[start]
    if start == 0:
        break
path.reverse()
num = len(path)
c, d = (path[(num+1)//2-1], path[(num+1)//2])
G[c].remove(d)
G[d].remove(c)
prev = [-1]*N
DFS0 = DFS(0)
prev = [-1]*N
if DFS0 > DFS(N-1):
    print("Fennec")
else:
    print("Snuke")

Measured memory_bytes: 174880
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int k,a,b;
signed main(){
	cin>>k>>a>>b;
	if(k<=a)cout<<1<<endl;
	else if(a<=b)cout<<-1<<endl;
	else{
		int c=(k-a+(a-b)-1)/(a-b);
		cout<<c*2+1<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int K, N; 
  cin >> K >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A));

  cout << max(A[N-1]-(K-A[N-1])-1, 0ll) << "\n";


  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int N, ch=0;
scanf("%d",&N);
int P[100];
for(int i=0;i<N;i++){
    scanf("%d",&P[i]);
}
for(int i=1;i<=N;i++){
    if(i==P[i-1]) ch++;
}
if(ch==N-2 ||ch==N)printf("YES\n");
else printf("NO\n");
return 0;
}

Measured memory_bytes: 128
N = int(input())
X = list(map(int, input().split()))
X = sorted(X)

# print(N)
# print(X)

minX, maxX = min(X), max(X)
min_cost = 1e10

for p in range(minX, maxX + 1):
    cost = sum([(x - p) ** 2 for x in X])
    min_cost = min(min_cost, cost)

print(min_cost)


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

int main() {
  int N, a, b;
  cin >>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  if(N%2==0){
    for(int j=0;j<N;j=j+2){
      a = a+vec.at(j)-vec.at(j+1);
    }
    cout <<a <<endl; 
  }
  else {
    for(int j=0;j<N-1;j=j+2){
      b = b+vec.at(j)-vec.at(j+1);
    }
      b=b+vec.at(N-1);
    cout <<b <<endl;
  }
  
}


Measured memory_bytes: 256
n,w=map(int,input().split())
l=(n*1000)+1
dp=[9999999999]*(l)
dp[0]=0
for i in range(n):
	wt,val=map(int,input().split())
	for j in range(l-1,val-1,-1):
		dp[j]=min(dp[j],dp[j-val]+wt)
for i in range(l-1,-1,-1):
	if dp[i]<=w:
		print(i)
		exit()

Measured memory_bytes: 43132
n,k=map(int,input().split())
*a,= map(int,input().split())
a=sorted(a)
limit=10**5+5
dp=[False]*limit

for i in range(limit):
    if dp[i]==False:
        for j in range(n):
            if i+a[j]<limit:
                dp[i+a[j]]=True
if dp[k]:
    print('First')
else:
    print('Second')

Measured memory_bytes: 70580
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author dilip
 */

/*
*   author : dilip
*   time : 23-06-2019 22:11
*/

#include <iostream>
#include <fstream>

#include <iostream>
#include<stdio.h>
#include<bits/stdc++.h>

#define M 1000000007
#define ll long long
using namespace std;
int h,w;
//char a[1005][1005];
//vector<vector<ll>> dp(1005,vector<ll>(1005,0));

class HGrid1 {
public:
	void solve(std::istream& in, std::ostream& out) {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        in >> h >> w;
        vector<string> grid(h);
        for(int i=0;i<h;i++)
            in >> grid[i];
        vector<vector<int>> dp(h+1,vector<int>(w+1,0));

        dp[1][1] = 1;
        for(int i=0;i<h;i++){
        	for(int j=0;j<w;j++){
        		if(i == 0 && j == 0)continue;
        		if(grid[i][j] == '#')continue;
        		dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j])%M;
        	}
        }

        out << dp[h][w];

	}
};


int main() {
	HGrid1 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 5248
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String str = scan.next();
		int num = Integer.parseInt(str);
      	str = scan.next();
      	int numb = Integer.parseInt(str);
      	
		if(num % 2 == 0){
			System.out.println("Even");
		}else if(numb % 2 == 0){
			System.out.println("Even");
		}else{
			System.out.println("Odd");
		}
	}
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
    char str[4];
    int i;
    scanf("%s", str);
    i = strchr(str, '7');
    if (i != 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


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

using namespace std;

int main(){
	
	int n,m,a=0;
	cin>>n>>m;
	if(n>=2){
		a+=((n)*(n-1))/2;
	}
	if(m>=2){
		a+=((m)*(m-1))/2;
	}
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
l, r=map(int, input().split())
x, y=l//2019, r//2019
p=0
if x==y:
	p=2019
	for i in range(l, r):
		for j in range(i+1, r+1):
			p=min(p, (((i%2019)*(j%2019))%2019))
print(p)

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

#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())

using namespace std;

int main() {
  int r;
  cin >> r;
  
  string result;
  if (r < 1200) {
    result = "ABC";
  } else if (r < 2800) {
    result = "ARC";
  } else {
    result = "AGC";
  }
  
  cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#define loop(i,b,n) for(int i = b; i<n; i++)
#define rep(i,n)  loop(i,0,n)
#define INF 1e7
#define MAX 1e7
using namespace std;

int main (){
    char temp,a,g1,g2,temp2,mem = 'A';
    while(cin >>temp >>g1>>temp2 ){
        if(mem  == temp)
            mem = temp2;
        else if(mem == temp2)
            mem = temp;
    }
    cout << mem << endl;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define pb(x)						push_back(x)
using namespace std;
const int INF = 0x7f7f7f7f;
vector<vector<int> > adj;
vector<bool> vis;
void dfs(int v)
{
	vis[v] = true;
	for(int i = 0; i<adj[v].size(); i++)
	{
		int child = adj[v][i];
		if(!vis[child])
			dfs(child);
	}
}
int connectedComponents(int n)
{
	int cnt = 0;
	for(int i = 1; i<=n; i++)
	{
		if(!vis[i])
		{
			cnt++;
			dfs(i);
		}
	}
	return cnt;
}
int main()
{
	int n,e;
	scanf("%d%d",&n,&e);
	adj.assign(n+1,vector<int>());
	vis.assign(n+1,false);
	for(int i = 0;i<e;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);
	}	
	int ans = connectedComponents(n);
	printf("%d\n",ans-1);
	
    return 0;
}

Measured memory_bytes: 9620
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#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 ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;

int N;

vector<long long> h(110000);

long long dp[110000];

long long dfs(int k) 
{

	if (k >=N)return INF;
	if (k == N - 1)return 0;
	if (dp[k] != -1)return dp[k];

	long long step1 = dfs(k + 1) + abs(h[k + 1] - h[k]);
	long long step2 = dfs(k + 2) + abs(h[k + 2] - h[k]);

	return dp[k] = min(step1, step2);

}


int main() {

	

	cin >> N;

	

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

	REP(i, 110000) {
		dp[i] = -1;
	}

	cout << dfs(0) << endl;

	return 0;
}

Measured memory_bytes: 6656
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RBLF
int n,m,cnt;
vs in;
vvi num;
void dfs(int a,int b,char c){
	in[a][b]='!';
	num[a][b]=cnt;
	rep(i,8){
		if(c=='.'&&i==4)break;
		int x=a+dx[i];
		int y=b+dy[i];
		if(x<0||x>=n+2||y<0||y>=m+2)continue;
		if(in[x][y]!=c)continue;
		dfs(x,y,c);
	}
}
vvi f(){
	cin>>n>>m;
	if(!n)return vvi(0);
	in=vs(n+2,string(m+2,'.'));
	num=vvi(n+2,vi(m+2));
	vvi G(1);
	rep(i,n){
		string s;cin>>s;
		in[i+1]="."+s+".";
	}
	cnt=0;
	
	rep(i,n+2)rep(j,m+2)if(in[i][j]!='!'){
		if(cnt){
			G[num[i][j-1]].pb(cnt);
			G.pb(vi(0));
		}
		dfs(i,j,in[i][j]);
		cnt++;
	}
	return G;
}
vvi G;
vi Rand(100000);
ll MOD=1000000009;
ll Hash(int a,int b){
	vi in;
	ll out=1;
	rep(i,G[a].size())(out*=(Rand[b]+Hash(G[a][i],b+1))%MOD)%=MOD;
	return out;
}
int main(){
	random_device rnd;
	rep(i,100000)Rand[i]=rnd()%MOD;
	while(1){
		G=f();
		if(G.size()==0)break;
		ll A=Hash(0,0);
		G=f();
		ll B=Hash(0,0);
//		cout<<A<<" "<<B<<endl;
		if(A==B)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}












Measured memory_bytes: 3928
def inpl():
    return list(map(int, input().split()))


N = int(input())
A = inpl()

a1 = A[0]
for i in range(1, N - 1):
    if i % 2 == 0:
        a1 += A[i]
    else:
        a1 -= A[i]

a1 = a1 + A[-1]

ans = [0 for i in range(N)]
ans[0] = a1

for i in range(1, N):
    ans[i] = (A[i - 1] - ans[i - 1] // 2) * 2

print(" ".join(map(str, ans)))


Measured memory_bytes: 19096
#include<stdio.h>
 int main(void){
     int n,k,ans=0;
     int d[100],a[100],cnt[101];
     int b[100][100];
     scanf("%d %d",&n,&k);
     for(int i=0;i<n;i++){
         scanf("%d",&d[i]);
          for(int j=0;j<d[i];j++){
              scanf("%d",&b[i][j]);
              cnt[b[i][j]]++;
            }
       }
       for(int i=1;i<=n;i++){
           if(cnt[i]==0){
               ans++;
           }
       }
       printf("%d",ans);
       return 0;
 }

Measured memory_bytes: 1764
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int m,d;
  cin>>m>>d;
  int cnt=0;
  for (int i = 1; i <= m; ++i)
  {
    for (int j = 11; j <= d; ++j)
    {
      int d1=j%10;
      int d2=(j-d1)/10;
      if(d1>=2&&d2>=2&&i==d2*d1) cnt++;
    }
  }
  cout<<cnt;
}

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

int main() {
	LL n;
	cin>>n;
	LL cnt=0;
	LL a=n/500;
	cnt+=1000*a;
	n=n-500*a;
	LL b=n/5;
	cnt+=b*5;
	cout<<cnt<<endl;
	return 0;
}

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

int main() {
  int N;
  int d[60];
  cin >> N;

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

  int total = 0;
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      if(i == j)
        continue;
      if(i > j)
        continue;
      total += d[i] * d[j];
    }
  }
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 256
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define count(v,x) count(v.begin(),v.end(),x)
#define find(v,x) find(v.begin(),v.end(),x)


priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

int calc(int x){
    int ret=0;
    for(int i=1;i*i<=x;i++){
        if(x%i==0){
            ret++;
            if(x/i!=i)ret++;
        }
    }
    return ret;
}


void solve(){
    int n;
    cin >> n;
    int ans=0;
    for(int i=1;i<=n;i+=2){
        if(calc(i)==8)ans++;
    }
    cout << ans << endl;
}

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




Measured memory_bytes: 3600
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	vi arr(n);
	for(int &i:arr)cin>>i;
	int cnt = 0;
	while(1) {
		bool set = false;
		int st = -1;
		int en = -1;
		int mi =INT_MAX;
		for(int i=0;i<n;i++) {
			if(!set&&arr[i]==0)continue;
			if(set&&arr[i]==0){break;}
			en =i;
			mi=min(arr[i],mi);
			if(!set){st = i;set=true;}
		}
		if(!set)break;
		for(;st<=en;st++)arr[st]-=mi;
		cnt+=mi;
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3620