akhauriyash/Code-Regression huggingface dataset:
import sys

input = sys.stdin.buffer.readline

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


class SegmentTree:
    ele = 10 ** 10
    func = min
    # SEG木は1-index
    # Aに関しては0-index

    def __init__(self, n):  # Aは0-idx
        self.n = n
        self.num = 2 ** ((self.n - 1).bit_length())
        self.SEG = [self.ele] * (2 * self.num)

    def search(self, idx):
        return self.SEG[idx + self.num]

    def initialize(self, A):
        for i in range(self.n):
            self.SEG[i + self.num] = A[i]
        for i in range(self.num - 1, 0, -1):
            self.SEG[i] = self.func(self.SEG[2 * i], self.SEG[2 * i + 1])

    def update(self, idx, val):
        idx += self.num
        self.SEG[idx] = val
        idx //= 2
        while idx:
            self.SEG[idx] = self.func(self.SEG[2 * idx], self.SEG[2 * idx + 1])
            idx //= 2

    def query(self, left, right):
        # maspy式。開区間のママ処理する
        # left, rightで値を分けているのは交換法則不成立のときのため
        # 開区間→Rが奇数→右端が偶数→1ずらしてから計算
        # 　下から上への遷移は2で割る
        # juppy氏は閉区間に直していた
        resleft = self.ele
        resright = self.ele
        left += self.num
        right += self.num
        while right - left > 0:
            if left % 2 == 1:
                resleft = self.func(resleft, self.SEG[left])
                left += 1
            if right % 2 == 1:
                right -= 1
                resright = self.func(resright, self.SEG[right])
            left //= 2
            right //= 2
        return self.func(resleft, resright)


ans = 0

tate = SegmentTree(n)
yoko = SegmentTree(n)

for i in range(q):
    s, x = map(int, input().split())
    x -= 1
    if s == 1:
        temp = tate.query(x, n)
        # print("t", i, temp)
        if temp == 10 ** 10:
            temp = n - 1
        now = yoko.search(temp)
        now = min(now, x)
        yoko.update(temp, now)
        ans += temp - 1
    else:
        temp = yoko.query(x, n)
        # print("t", i, temp)
        if temp == 10 ** 10:
            temp = n - 1
        now = tate.search(temp)
        now = min(now, x)
        tate.update(temp, now)
        ans += temp - 1
    # print("a", i, temp - 1)
ans = (n - 2) ** 2 - ans
assert ans >= 0
print(ans)


Measured memory_bytes: 103696
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <limits>
#include <utility>
#include <algorithm>
#include <tuple>
#include <limits>

typedef long long ll;

int main(int argc, char *argv[])
{
    int n;

    std::cin >> n;

    std::vector<ll> count(n + 1, 0);
    for (int x = 1; x * x + 2 * x + 3 <= n; x++) {
        for (int y = 1; y <= x; y++) {
            if (x * x + y * y + 1 + x * y + y + x > n) {break;}
            for (int z = 1; z <= y; z++) {
                ll a = x * x + y * y + z * z + x * y + y * z + z * x;
                if (a > n) {break;}
                if (x == y && y == z) {
                    count[a]++;
                } else if (x == y || y == z || z == x) {
                    count[a] += 3;
                } else {
                    count[a] += 6;
                }
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        std::cout << count[i] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3676
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
#include <ctype.h>
long long ruiseki[600][600] = {};
int main() {
	int n, m, query;
	cin >> n >> m >> query;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		ruiseki[a][b]++;
	}
	for (int i = 500; i >= 0; --i) {
		for (int q = 0; q <= 500; ++q) {
			ruiseki[i][q] += ruiseki[i + 1][q];
		}
	}
	for (int i = 0; i < query; ++i) {
		int a, b;
		cin >> a >> b;
		int ans = 0;
		for (int q = 0; q <= b; ++q) {
			ans += ruiseki[a][q] - ruiseki[b+1][q];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3328
<?php

$N = trim(fgets(STDIN));
$S_ar = ['A', 'C', 'G', 'T'];
$N_ar = str_split($N);
$count = 0;
//切り出し開始位置と終了位置の組み合わせ
$len_check = [];
for($i=0; $i<count($N_ar); $i++){
    for($j=$i; $j<count($N_ar); $j++){
        $str = substr($N, $i, ($j-$i)+1);
        $is_check = true;
        foreach(str_split($str) as $s){
            if(!in_array($s, $S_ar)){
                $is_check = false;
                break;
            }
        }
        if($is_check) {
            //echo $str.PHP_EOL;
            $len_check[] = strlen($str);
        }
        /*for($k=$i; $k<=$j; $k++){
            
            if(!in_array($N_ar[$k], $S_ar)){
                $is_check = false;
                break;
            }
        }
        if($is_check) $count++;*/
    }
}
if(count($len_check) > 0){
    echo max($len_check);
}else{
    echo 0;
}

?>

Measured memory_bytes: 16096
n, m = map(int, input().split())
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
for i in [int(input()) for _ in range(m)]:
    dp[i] = -1
for i in range(n + 1):
    if i < 2:
        if dp[i] == -1:
            dp[i] = 0
    else:
        if dp[i] == -1:
            dp[i] = 0
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
print(dp[n])


Measured memory_bytes: 7756
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

pair<int,int> p[200000];

int main(void) {
    int i, w, h;
    scanf("%d%d",&w,&h);
    REP (i,w) {
        int x;
        scanf("%d",&x);
        p[i] = make_pair(x,0);
    }
    REP (i,h) {
        int x;
        scanf("%d",&x);
        p[i+w] = make_pair(x,1);
    }
    sort(p,p+w+h);
    int rw = w, rh = h;
    ll ans = 0;
    REP (i,w+h) {
        if (p[i].second == 0) {
            ans += (ll) p[i].first * (rh + 1);
            rw--;
        }
        else {
            ans += (ll) p[i].first * (rw + 1);
            rh--;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1920
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

signed main()
{
	int N;
	cin >> N;
	int cnt = 0;
	REP(i, N) if ((i + 1) % 2 == 1)cnt++;
	cout << fixed << setprecision(10) << cnt / (double)N;
}



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

#define x first
#define y second
#define x1 X1 
#define x2 X2
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
inline int read ()
{
	int sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

const int MAXN = 300 + 10;

int N, A[MAXN][MAXN], P[MAXN];

char S[MAXN];

inline int add (int x, int len)
{
	x += len;
	if (1 <= x && x <= N) return x;
	if (x <= 0) return x + N;
	return x - N;
}

int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	N = read();
	for (int i = 1; i <= N; ++i)
	{
		scanf("%s", S);
		for (int j = 1; j <= N; ++j)
			A[i][j] = S[j - 1] - 'a' + 1;
	}
	int ans = 0;
	for (int k = 1; k <= N; ++k)
	{
		int now = k;
		for (int i = 1; i <= N; ++i) P[i] = now++, now = now == N + 1 ? 1 : now;
		for (int i = 1; i < N; ++i)
			for (int j = i + 1; j <= N; ++j)
			{
				int sx = i, sy = j + k - 1;
				if (sy > N) sy -= N;
				int len = sy - P[i];
				if (len < 0) len += N;
				int x = add (sx, len), y = add (sy, -len);
				if (A[sx][sy] != A[x][y]) goto AFO;
			}
		ans += N;
AFO:;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
z='abcdefghijklmnopqrstuvwxyz'
e=lambda x,i,j:z[(z.index(x)*i+j)%26]
def f():
 for i in range(1,26,2):
  for j in range(26):
   if''.join(e(c,i,j)for c in'that')in s or''.join(e(c,i,j)for c in'this')in s:return(i,j)
def g(x,y,s=0,t=1):
 q,r=x//y,x%y
 return g(y,r,t,s-q*t) if r else t
for _ in[0]*int(input()):
 s=input()
 a,b=f()
 h=g(26,a)
 print(''.join(z[h*(z.index(c)-b)%26]if c in z else c for c in s))


Measured memory_bytes: 5600
#include<stdio.h>

int main(){

    int n;
    scanf("%d",&n);
    int w[n];
    for(int i=0;i<n;i++){
        scanf("%d",&w[i]);
    }
    
    int r_sum,l_sum;
    int min=1000000;
    int dif;
    for(int i=0;i<n-1;i++){
        r_sum=0;
        l_sum=0;
        for(int j=0;j<=i;j++){
            r_sum+=w[j];
        }
        for(int k=i+1;k<n;k++){
            l_sum+=w[k];
        }
        dif=l_sum-r_sum;

        if(dif<0){
            dif=dif*(-1);
        }
        if(dif<min){
            min=dif;
        }
    }
    printf("%d\n",min);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
int main(){
  ll i, j;
  ll n, m;
  cin >> n >> m;
  cout << n - m + 1 << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    map<string, int> m;
    int n; cin >> n;
    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        if(m.find(s) != m.end()) continue;
        else {
            m.insert(pair<string, int>(s, 1));
        }
    }
    cout << m.size() << endl;
    return 0;
}

Measured memory_bytes: 19220
import numpy as np
import numba

@numba.njit("(i8,i8,i8,i8[:,:])", cache=True)
def solve(R, C, K, RCV):
    # dp[y][x][n]
    M = np.zeros((R+1, C+1), dtype=np.int64)
    for i in range(K):
        r, c, v = RCV[i]
        M[r, c] = v
    dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
    for y in range(1, R+1):
        for x in range(1, C+1):
            for n in range(4):
                if n == 0:
                    dp[y, x, n] = max(
                        dp[y, x-1, 0],
                        dp[y-1, x, :].max()
                    )
                if n > 0:
                    dp[y, x, n] = max(
                        dp[y, x-1, n],
                        dp[y, x-1, n-1] + M[y, x],
                        dp[y-1, x, :].max() + M[y, x]
                    )
    ans = dp[R, C].max()
    print(ans)

import sys
def main():
    R, C, K = map(int, input().split())
    RCV = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(K, 3)
    solve(R, C, K, RCV)

main()


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

#define ll long long
#define forn(i,n) for(int i=0; i<n; i++)
#define fors(i,s,n) for(int i=s; i<n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()

using namespace std;

const int INF = 1e8+1;

int main(){
    int n;
    cin >> n;
    map<string,int>words;
    words["AC"]=0;
    words["WA"]=0;
    words["TLE"]=0;
    words["RE"]=0;
    forn(i,n){
    string aux;
    cin >> aux;
    words[aux]++;
    }
    cout << "AC x " <<words["AC"] << endl;
    cout << "WA x " <<words["WA"] << endl;
    cout << "TLE x " <<words["TLE"] << endl;
    cout << "RE x " <<words["RE"] << endl;

}


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

#define ll long long
#define fi first
#define sec second

ll n,m,k,x,x2,y,y2,sol=0;
char c;
string s="",s2,o;
vector <ll> V;

int main()
{
    cin >> n;
    while (1){
        x=n%26;
        if (x==0) x=26;
        o=('a'+x-1);
        s=o+s;
        if (n<=26) break;
        n/=26;
        if (x==26) n--;
    }
    cout << s;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int n,m; cin >> m >> n;
    vint a(n); rep(i,n) cin >> a[i];

    int ma=MAX(a),other=SUM(a)-ma;
    cout<<max(0LL,ma-other-1)<<endl;   
}

Measured memory_bytes: 3592
def main():
  n = int(input())
  #s = input()
  #s = input().split()
  #a,b,c,d = list(map(int,input().split()))
  s = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  for i in set(s):
    count += 1
  print(count)
  
if __name__ == '__main__':
  main()

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

string S;
ll K;

signed main()
{
    cin >> S >> K;
    // 先頭から連続する 1 の数
    ll one = 0;
    REP(i, S.length()) {
        if(S[i] != '1') { break; }
        one++;
    }
    if(one >= K) {
        printf("1\n");
    } else {
        printf("%c\n", S[one]);
    }

    return 0;
}


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

grid = [[0 for _ in range(9)] for _ in range(9)]
ans = 0
for i in range(1, n + 1):
    if i % 10 == 0:
        continue
    else:
        s = str(i)
        grid[int(s[0]) - 1][int(s[-1]) - 1] += 1

for i in range(9):
    for j in range(9):
        ans += grid[i][j] * grid[j][i]
print(ans)


Measured memory_bytes: 3060
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1000000007
#define mxval 1e9 + 7
#define grt [](auto x,auto y){return x>y;}
#define pii pair<int,int>
/*********VARIABLE****************/
using namespace std;
int i,j,n,m,k,l,q,t,a,b,sum[3],tot[3],cnt[3];
/*********FUNCTIONS**************/
int powom(int a,int b) {
    int result = 1;
    while (b > 0) {
        if (b & 1)
            result = result * a;
        a = a * a;
        b >>= 1;
    }
    return result;
}
/***********MAIN**************/
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if((i+1)%2==0&&s[i]=='R'){
            cout<<"No";
            return 0;
        }
        if((i+1)%2!=0&&s[i]=='L'){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}
//.........

Measured memory_bytes: 256
import java.util.Scanner;

    public class Main{
        public void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=0;i<n;i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            int b = sc.nextInt();
            int p = sc.nextInt();
           
            int kin = x*b+y*p;
            
            if(b>=5 && p>=2){
                kin = (x*b+y*p)*4/5;
            }else{
                if(b<5){
                    b=5;
                }
                if(p<2){
                    p=2;
                }
                int wari = (x*b + y*p)*4/5;
                
                if(kin>wari){
                    kin = wari;
                }
            }
                System.out.println(kin);
        }
        }
    public static void main(String[]args){
    Main obj = new Main();
    obj.solve();
    }
    }

Measured memory_bytes: 23284
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 







int dp[200][200];

int main()
{
     int h,w;
     cin>>h>>w;
     char s[h+2][w+2];
     for(int i=0;i<=h+1;i++){
          for(int j=0;j<=w+1;j++)s[i][j]='.';
     }
     for(int i=1;i<=h;i++){
          string t;cin>>t;
          for(int j=0;j<t.length();j++){
               s[i][j+1]=t[j];
          }
     }
     for(int j=1;j<=w;j++){
          if(s[1][j]=='.')dp[1][j]=dp[1][j-1];
          else if(s[1][j]=='#'){
               if(s[1][j-1]=='.')dp[1][j]=1+dp[1][j-1];
               else dp[1][j]=dp[1][j-1];
          }
     }
     for(int i=1;i<=h;i++){
          if(s[i][1]=='.')dp[i][1]=dp[i-1][1];
          else if(s[i][1]=='#'){
               if(s[i-1][1]=='.')dp[i][1]=1+dp[i-1][1];
               else dp[i][1]=dp[i-1][1];
          }
     }
     for(int i=1;i<=h;i++){
          for(int j=1;j<=w;j++){
               if(i==1||j==1)continue;
               if(s[i][j]=='.'){
                    dp[i][j]=min(dp[i][j-1],dp[i-1][j]);
               }
               else if(s[i][j]=='#'){
                    if(s[i][j-1]=='.'&&s[i-1][j]=='.'){
                         dp[i][j]=1+min(dp[i][j-1],dp[i-1][j]);
                         
                    }
                    else if(s[i][j-1]=='.'&&s[i-1][j]=='#'){
                         dp[i][j]=min(1+dp[i][j-1],dp[i-1][j]);
                    }
                    else if(s[i][j-1]=='#'&&s[i-1][j]=='.'){
                         dp[i][j]=min(dp[i][j-1],1+dp[i-1][j]);
                    }
                    else{
                         dp[i][j]=min(dp[i][j-1],dp[i-1][j]);
                    }
               }
          }
     
     }
     /*for(int i=1;i<=h;i++){
          for(int j=1;j<=w;j++)cout<<dp[i][j]<<" ";
          cout<<"\n";
     }*/
     cout<<dp[h][w];
}


























Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main (String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        List<Integer> nums = new ArrayList<>();
        for (String s : str) {
            nums.add(Integer.valueOf(s));
        }
        int count = 0;
        for (int i = nums.get(0); i <= nums.get(1); i++) {
            if (nums.get(2) % i == 0) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 24548
data = input().split()
N = int(data[0])
Y = int(data[1])

flag = False

for a in range(N + 1):
    if flag == True:
        break
    for b in range(N + 1 - a):
        if flag == True:
            break
        c = N - a - b
        if c < 0:
            continue
        elif a * 10000 + b * 5000 + c * 1000 == Y:
            print(str(a) + " " + str(b) + " " + str(c))
            flag = True

if flag == False:
    print("-1 -1 -1")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define big 1000000007
vector<int> data;
vector<int> memo(200000);
vector<int> done(200000);
ll n, k;
ll dp(int n)
{
    if (done[n] == 1)
    {
        return memo[n];
    }
    else
    {
        ll res;
        ll count = 0;
        for (int i = 1; i < k + 1; i++)
        {
            if (n - i < 0)
            {
                continue;
            }
            count = dp(n - i) + labs(data[n] - data[n - i]);
            if (i == 1)
            {
                res = count;
            }
            else
            {
                res = min(res, count);
            }
        }
        done[n] = 1;
        memo[n] = res;
        return res;
    }
}
int main()
{

    cin >> n >> k;
    data.resize(n);
    rep(i, n)
    {
        cin >> data[i];
        //  cout << data[i];
    }
    // cout << dp(n - 1); //その場所まで行くのにかかる最小コスト
    cout << dp(n - 1);
}

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

using namespace std;

const int N = 3005, MOD = 1e9 + 7;
int n, dp[N][N], sum[N][N];
string s;

inline int add(int a, int b){
    a += b;
    if(a >= MOD)a -= MOD;
    return a;
}

inline int sub(int a, int b){
    a -= b;
    if(a < 0)a += MOD;
    return a;
}

// dp[i][j] -> number of permutations upto [1, i] with p[i] = j;

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

    cin>>n; cin>>s; s = '*' + s;

    dp[1][1] = sum[1][1] = sum[1][2] = 1;

    for(int i=2;i<=n;++i){
        for(int j=1;j<=i;++j){
            if(s[i - 1] == '<')dp[i][j] = sub(sum[i - 1][j - 1], sum[i - 1][0]);
            else dp[i][j] = sub(sum[i - 1][i], sum[i - 1][j - 1]);
            // cout<<dp[i][j]<<" ";
        }  
        // cout<<"\n";
        for(int j=1;j<=n;++j)sum[i][j] = add(sum[i][j - 1], dp[i][j]);
    }
    cout<<sum[n][n]<<"\n";
    return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll a,b;
  cin>>a>>b;
  if(b>=a)
  	deb("unsafe")
  else
  	deb("safe");
}

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

using namespace std;

int n , m , x , a[13][13] , ans = 1200005 , bo[13];

void go(int i , int aa[13] , int mm){
	if(i >= n) return;
	bool s = 1;
	for(int t = 0 ; t < m ; t++) if(aa[t] < x) s = 0;
	if(s){
		ans = min(ans , mm);
		return;
	}
	for(int t = i+1 ; t < n ; t++){
		for(int p = 0 ; p < m ; p++) aa[p] += a[t][p+1];
		go(t , aa , mm + a[t][0]);
		for(int p = 0 ; p < m ; p++) aa[p] -= a[t][p+1];
	}
}

int main(){
	cin>>n>>m>>x;
	for(int i = 0 ; i < n ; i++){
		cin>>a[i][0];
		for(int ii = 1 ; ii <= m ; ii++) cin>>a[i][ii];
	}
	for(int i = 0 ; i < n ; i++){
		for(int p = 0 ; p < m ; p++) bo[p] += a[i][p+1];
		go(i , bo , a[i][0]);
		for(int p = 0 ; p < m ; p++) bo[p] -= a[i][p+1];
	}
	cout<<(ans!= 1200005 ? ans : -1)<<endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int sum = 0;
  cin >> N;
  for (int n = 0; n < N; n++){
	int l, r;
    cin >> l >> r;
    sum += (r - l) + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import copy
def main():
    n,m = map(int,input().split())
    sc = []
    for i in range(m):
        s,c = map(int,input().split())
        sc.append([s,str(c)])
    if n==1:
        for i in range(10):
            flag = True
            tmp = str(i)
            tmp = list(tmp)
            tmp = ['0' for j in range(n-len(tmp))] + tmp
            for j in range(m):
                if tmp[sc[j][0]-1] !=sc[j][1]:
                    flag = False
            if flag:
                print(i)
                exit()
            
    else:        
        for i in range(10**(n-1),10**n):
            flag = True
            tmp = str(i)
            tmp = list(tmp)
            tmp = ['0' for j in range(n-len(tmp))] + tmp
            
            for j in range(m):
                if tmp[sc[j][0]-1] !=sc[j][1]:
                    flag = False
            if flag:
                print(i)
                exit()
    print('-1')
main()

Measured memory_bytes: 9328
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
#define BLACK 0
#define WHITE 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

Map prime;

void factrization(ll N) {
    for(ll i=2; i*i<=N; i++) {
        while(N%i==0) {
            prime[i]++;
            N/=i;
        }
    }
    
    if(N!=1) {
        prime[N]++;
    }
    
}

int main(void) {
    ll N, P;
    cin >> N >> P;
    ll ans=1;
    factrization(P);
    
    for(auto itr=prime.begin(); itr!=prime.end(); itr++) {
        if(itr->second>=N) {
            ans*=pow(itr->first, itr->second/N);
        }
        
    }
    
    
    pr(ans);
    
    
    
    
    
}


















Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    int l,r,d;

    cin >> l >> r >> d;
    int ans = 0;
    REP(i,l){
        if (i % d == 0) --ans;
    }
    REP(i,r+1){
        if (i % d == 0) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;



int main() {
	int n; cin >> n;
	vector<int> t(n), v(n);
	rep(i, 0, n) cin >> t[i];
	rep(i, 0, n) cin >> v[i];
	vector<double> dp(110, -1e9);
	dp[0] = 0;
	rep(i, 0, n) rep(j, 0, t[i]) {
		vector<double> sub(110, -1e9);
		rep(k, 0, v[i] + 1) {
			sub[k] = max(sub[k], dp[k] + k);
			if (k < v[i]) {
				sub[k] = max(sub[k], dp[k] + k + 0.25);
				sub[k + 1] = max(sub[k + 1], dp[k] + k + 0.5);
			}
			if (k > 0) sub[k - 1] = max(sub[k - 1], dp[k] + k - 0.5);
		}
		swap(dp, sub);
	}
	cout.precision(10);
	cout << fixed << dp[0] << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val m = scn.nextInt()
	val k = scn.nextInt()
	val uf = UF(n)
	val fs = IntArray(n){0}
	val bs = Array(n) { mutableSetOf<Int>() }
	repeat(m){
		val a = scn.nextInt()-1
		val b = scn.nextInt()-1
		uf.unite(a, b)
		fs[a]++
		fs[b]++
	}
	repeat(k){
		val c = scn.nextInt()-1
		val d = scn.nextInt()-1
		bs[c].add(d)
		bs[d].add(c)
	}
	val nums = mutableMapOf<Int, Int>()
	repeat(n){
		val r = uf.root(it, true)
		nums[r] = nums.getOrElse(r){0} + 1
	}
	val ans = IntArray(n){i ->
		val r = uf.root(i)
		nums[r]!! - fs[i] - bs[i].filter{uf.same(i, it)}.size - 1
	}
	print(ans.joinToString(separator = " "))
}

class UF(n: Int) {
	val arr: IntArray = IntArray(n){it}
	val fs: BooleanArray = BooleanArray(n){false}

	fun root(x: Int, memo: Boolean = false): Int{
		if (arr[x]!=x && !fs[x]) arr[x]=root(arr[x])
		if (memo) fs[x] = true
		return arr[x]
	}

	fun unite(x:Int, y:Int){
		val rx = root(x)
		val ry = root(y)
		if (rx==ry) return
		arr[rx] = ry
	}

	fun same(x: Int, y: Int): Boolean{
		return root(x) == root(y)
	}
}

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

int main() {
    string s;
    cin >> s;
    int price = 700;
    if(s[0] == 'o') price += 100;
    if(s[1] == 'o') price += 100;
    if(s[2] == 'o') price += 100;
   
    cout << price << endl;
}

Measured memory_bytes: 256
n=int(input())
s=input()
a=len(s)
if a%2==1:
  print("No")
else:
  b=a//2
  c=0
  for i in range(b):
    if s[i]!=s[i+b]:
      print("No")
      break
    else:
      c=c+1
  if c==b:
    print("Yes")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
int min=a[0],max=a[0];
  for(int i=0;i<n;i++){
    if(min>a[i]){
      min=a[i];
  }
    if(max<a[i]){
      max=a[i];
    }
  }
    cout<<max-min<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i, j, temp = 0, x[10];
	for (i = 0; i < 10; i++){
		//printf("山の高さ%d ", i + 1);
		scanf("%d", &x[i]);
	}
	for (i = 0; i < 10; i++){
		for (j = 9; j > i; j--){
			if (x[j] > x[j - 1]){
				temp = x[j - 1];
				x[j - 1] = x[j];
				x[j] = temp;
			}
		}
	}
	for (i = 0; i < 3; i++){
		printf("%d\n", x[i]);
	}
	
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
int main()
 {
 	int n,a;
 	cin>>n;	
 	a=n%10;
 	if(a==2||a==4|a==5||a==7||a==9)
 		cout<<"hon"<<endl;
 		
	else if(a==0||a==1|a==6||a==8)
 		cout<<"pon"<<endl;
 	else
 		cout<<"bon"<<endl;
 	return 0;
}
 	
 					

Measured memory_bytes: 3624
from itertools import groupby

N = int(input())
def fast_prime_factorization(n):
    # 素因数分解（ロー法）  O(n^(1/4) polylog(n))
    from subprocess import Popen, PIPE
    return list(map(int, Popen(["factor", str(n)], stdout=PIPE).communicate()[0].split()[1:]))


def egcd(a, b):
    # 拡張ユークリッド互除法
    # ax + by = gcd(a,b)の最小整数解を返す
    # 最大公約数はg
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


def a(n):
    if n == 1:
        return 1
    f = fast_prime_factorization(2*n)
    f2 = [v ** len(list(gr)) for v, gr in groupby(f)]
    l = len(f2)
    ans = 1<<62
    for s in range(1<<l):
        p = 1
        q = 1
        for i in range(l):
            if s>>i & 1:
                p *= f2[i]
            else:
                q *= f2[i]
        if p==1 or q==1:
            continue
        g, x, y = egcd(-p, q)
        a = abs(y) * q
        #print(p, q, x, y, a)
        if ans > a:
            ans = a
    return ans

#print(a(15**12))

print(a(N))


Measured memory_bytes: 10128
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		for(int i = 0; i < totalVertex; i++) {
			for(int j = 0; j < totalVertex; j++) {
				adjMatrix[i][j] = 0;
			}
		}
		for(int i = 0; i < totalVertex; i++) {
			LinkedList<Integer> temp = adjList.get(i);
			Iterator<Integer> it = temp.iterator();
			while(it.hasNext()) {
				int cur = it.next();
				adjMatrix[i][cur] = 1; 
			}
		}
		for(int row = 0; row < totalVertex; row++) {
			for(int col = 0; col < totalVertex; col++) {
				if(col == totalVertex-1) {
					System.out.print(adjMatrix[row][col]);
				} else {
					System.out.print(adjMatrix[row][col] + " ");
				}
			}
			System.out.println();
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}


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

void main()
{
    auto nw = readln.split.to!(long[]);
    auto N = nw[0];
    auto W = nw[1];
    long[][4] vs;
    long base_w;
    foreach (i; 0..N) {
        auto wv = readln.split.to!(long[]);
        auto w = wv[0];
        auto v = wv[1];
        if (i == 0) {
            base_w = w;
        }
        vs[w - base_w] ~= v;
    }

    foreach (i; 0..4) {
        sort!"a > b"(vs[i]);
        vs[i] = [0L] ~ vs[i];
        foreach (j; 1..vs[i].length) vs[i][j] += vs[i][j-1];
    }

    long r;
    foreach (i; 0..vs[0].length) {
        foreach (j; 0..vs[1].length) {
            foreach (k; 0..vs[2].length) {
                foreach (l; 0..vs[3].length) {
                    if (i * base_w + j * (base_w+1) + k * (base_w+2) + l * (base_w+3) > W) continue;
                    r = max(r, vs[0][i] + vs[1][j] + vs[2][k] + vs[3][l]);
                }
            }
        }
    }
    writeln(r);
}

Measured memory_bytes: 256
#include <iostream>

inline bool funcOutputCalc()
{
	static int a, b, result;
	static char op;
	std::cin >> a >> op >> b;
	
	switch (op) {
	case('+'):
		result = a + b;
		break;
	case('-'):
		result = a - b;
		break;
	case('*'):
		result = a * b;
		break;
	case('/'):
		result = a / b;
		break;
	case('?'):
		return false;
	}
	std::cout << result << std::endl;
	return true;
}

int main()
{
	while (funcOutputCalc());
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll m,n,i,j,k,l,p,q,a,b;
    ll ar[10005]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cin>>n;
    cout<<ar[n-1]<<endl;
}


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


int ans;
void kmp_maketable(const char *key, int *table)
{
    table[0]=-1;table[1]=0;
    int i=2,j=0;
    while(i==0 || key[i-1]) {
        if(key[i-1] == key[j]) {
            table[i++] = ++j;
        } else if(j>0) {
            j = table[j];
        } else {
            table[i++] = 0;
        }
    }
}

void kmp_search(const char *str, const char *key, const int *table)
{
    int i=0,j=0;
    while(str[i]) {
        if(str[i]==key[j]) {
            if(!key[j+1]) {
	      //                printf("B: %d\n", i-j);
	      ans++;
            }
            i++, ++j;
        } else if(j>0) {
            j = table[j];
        } else {
            i++;
        }
    }
}

int main(){

  int n;
  while(1){
    cin >> n;
    if(n==0)break;
    int m;
    cin >> m;
    char s[1000010],p[1000010];
    scanf("%s",s);

    for(int i=0;i<2*n+1;i++){
      if(i%2==0)p[i] = 'I';
      else p[i] = 'O';
    }
    p[2*n+1] = '\0';
    
    
    int table[1000010];
    //    string s,p = "IO";
    ans=0;
    kmp_maketable(p, table);
    kmp_search(s, p, table);
    
    cout << ans << "\n";
  }

}

Measured memory_bytes: 3576
while True :
    try :
        y, m, d = map(int, input().split())
    except EOFError :
        break
    
    if y < 1868 :
        print("pre-meiji")
    elif y == 1868 and m < 9 :
        print("pre-meiji")
    elif y == 1868 and m == 9 and d < 8 :
        print("pre-meiji")
    elif y < 1912 :
        print("meiji", y-1867, m, d)
    elif y == 1912 and m < 7 :
        print("meiji", y-1867, m, d)
    elif y == 1912 and m == 7 and d < 30 :
        print("meiji", y-1867, m, d)
    elif y < 1926 :
        print("taisho", y-1911, m, d)
    elif y == 1926 and m < 12 :
        print("taisho", y-1911, m, d)
    elif y == 1926 and m == 12 and d < 25 :
        print("taisho", y-1911, m, d)
    elif y < 1989 :
        print("showa", y-1925, m, d)
    elif y == 1989 and m == 1 and d < 8 :
        print("showa", y-1925, m, d)
    else :
        print("heisei", y-1988, m, d)


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

int main() {
    ll L, R;
    cin >> L >> R;
    if(L*R<2019){
        cout << L*(L+1) << endl;
        return 0;
    }

    map<ll, ll> mp;
    for(ll i=L; i<=min(L+2019, R) ; i++){
        ll aa = i%2019;
        mp[aa]++;
    }

    int ans = 2019;
    for(int i=0; i<2018; i++){
        if(!mp[i]){
            continue;
        }
        for(int j=i+1; j<2019; j++){
            if(!mp[j]){
                continue;
            }
            ans = min(i*j%2019, ans);
        }
    }

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

Measured memory_bytes: 384
dbflag=""

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = -1

N = int(readline())

bag = set()

for i in range(0,N):
	d = int(readline())
	bag.add(d)

result = len(bag)

print(result)

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);

void go(){
	int n,a,b;cin>>n>>a>>b;
	cout << min({a*n,b});
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


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

N, Q = map(int, input().split())
graph = [[] for _ in range(N + 1)]
cnt = [0] * (N + 1)

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

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

wait = [1]
parent = [0] * (N + 1)
while wait:
    temp = wait.pop()

    # 頂点tempについて
    for i in graph[temp]:
        if i != parent[temp]:
            parent[i] = temp
            wait.append(i)
            cnt[i] += cnt[temp]


print(' '.join(map(str, cnt[1:])))

Measured memory_bytes: 66944
#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 temp = 1;
  for(int i = 0; i < N; i++)
  {
    temp = vec.at(temp - 1);
    if(temp == 2)
    {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 640
'''
Created on 2020/08/17

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N=int(pin())
  a=list(map(int,pin().split()))
  ans=0
  for i in a:
    if i%2==1:
      continue
    t=i
    while True:
      if t%2==0:
        t=t//2
        ans+=1
      else:
        break
  print(ans)
  return

main()


Measured memory_bytes: 10104
import java.io.*;
    import java.util.StringTokenizer;

    public class Main {

        private static void solver(InputReader sc, PrintWriter out) {
            String s = sc.next();
            if(s.charAt(2)==s.charAt(3) && s.charAt(4)==s.charAt(5))
                out.println("Yes");
            else
                out.println("No");
        }

        public static void main(String[] args) {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            InputReader in = new InputReader(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            solver(in, out);
            out.close();
        }
        static class InputReader {
            public BufferedReader reader;
            public StringTokenizer tokenizer;

            public InputReader(InputStream stream) {
                reader = new BufferedReader(new InputStreamReader(stream), 32768);
                tokenizer = null;
            }

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

            public int nextInt() {
                return Integer.parseInt(next());
            }
            public long nextLong() {
                return Long.parseLong(next());
            }
        }
    }


Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std;
int a1,a2,a3;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a1>>a2>>a3;
	if(a1+a2+a3>=22)
		cout<<"bust"<<endl;
	else
		cout<<"win"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
#define N 100011
int n;
int prim[N],cnt;
bool isp[N];
ll a[N];
ll b[N],c[N];
map<ll,int>mp,vis;
int main()
{
	for(int i=2;i<=2300;i++)isp[i]=1;
	for(int i=2;i<=2300;i++)
	{
		if(isp[i])prim[++cnt]=i;
		for(int j=1;j<=cnt&&prim[j]*i<=2300;j++)
		{
			isp[prim[j]*i]=0;
			if(i%prim[j]==0)break;
		}
	}
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		ll x=1,y=1;
		for(int j=1;j<=cnt;j++)if(a[i]%prim[j]==0)
		{
			int ct=0;
			while(a[i]%prim[j]==0)a[i]/=prim[j],ct++;
			ct%=3;
			for(int ii=0;ii<ct;ii++)x*=prim[j];
			for(int ii=0;ii<(3-ct)%3;ii++)y*=prim[j];
		}
		ll te=sqrt(a[i]);
		if(te*te==a[i])x*=a[i],y*=te;
		else x*=a[i],y*=a[i]*a[i];
		mp[x]++;
		b[i]=x,c[i]=y;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(!vis[b[i]])
		{
			vis[b[i]]=1;vis[c[i]]=1;
			if(b[i]==c[i])ans++;
			else ans+=max(mp[b[i]],mp[c[i]]);
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 27648
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

ll a[200001] = {};
ll b[200001] = {};

int main() {
	ll N, M; cin >> N >> M;
	rep(i, 0, M) {
		ll A, B;
		cin >> A >> B;
		if (A == 1) {
			a[B] = 1;
		}
		if (B == N) {
			b[A] = 1;
		}
	}
	rep(i, 2, N) {
		if (a[i] == 1 && b[i] == 1) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;

	return 0;
}

Measured memory_bytes: 3328