akhauriyash/Code-Regression huggingface dataset:
import sys
import collections

N = int(input())
S = [ch for ch in input()]
counter = collections.Counter(S)
if len(counter.keys()) != 3:
    print(0)
    sys.exit()
total = 1
for k, v in counter.items():
    total *= v

for i in range(len(S)):
    l, r = i - 1, i + 1
    while 0 <= l and r < len(S):
        if len(set([S[i], S[l], S[r]])) == 3:
            total -= 1
        l -= 1
        r += 1
print(total)

Measured memory_bytes: 68752
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int n,i,j,k,u,v,c,root,val;
int son[100005],Next[200005],ed[200005],len[200005],tot;
int size[100005],heavy[100005];
bool vis[100005];
long long ans;

void dfs(int x)
{
	vis[x]=true;
	size[x]=1;
	for(int i=son[x];i;i=Next[i])
	if(!vis[ed[i]])
	{
		dfs(ed[i]);
		size[x]+=size[ed[i]];
		if(size[ed[i]]>heavy[x])heavy[x]=size[ed[i]];
	}
	if(n-size[x]>heavy[x])heavy[x]=n-size[x];
	if(heavy[x]<val)val=heavy[x],root=x;
	vis[x]=false;
}

void dfs2(int x,long long deep)
{
	vis[x]=true;
	size[x]=1;ans+=deep*2;
	for(int i=son[x];i;i=Next[i])
	if(!vis[ed[i]])
	{
		dfs2(ed[i],deep+len[i]);
		size[x]+=size[ed[i]];
	}
}

int main()
{
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d%d",&u,&v,&c);
		++tot;Next[tot]=son[u];son[u]=tot;ed[tot]=v;len[tot]=c;
		++tot;Next[tot]=son[v];son[v]=tot;ed[tot]=u;len[tot]=c;
	}
	val=n;
	dfs(1);
	dfs2(root,0);
	val=1000000000;
	for(i=son[root];i;i=Next[i])
	if(size[ed[i]]==n/2&&n%2==0)
	{
		printf("%lld\n",ans-len[i]);
		return 0;
	}
	else
	{
		if(len[i]<val)val=len[i];
	}
	printf("%lld\n",ans-val);
}

Measured memory_bytes: 6400
s = input()
before = ("Heisei")
after = ("TBD")
if s[6] == "1" and s[5] == "0":
    print(before)
elif s[6] == "2" and s[5] == "0":
    print(before)
elif s[6] == "3":
    print(before)
elif s[6] == "4":
    print(before)
else:
    print(after)

Measured memory_bytes: 3060
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,x,y,ans;
void solve()
{
    string s,t;cin>>s>>t;
    map<char,char>mp,mp1;
    for(char i='a';i<='z';i++)
        mp1[i]=mp[i]='A';
    for(int i=0;i<s.size();i++)
    {
        if(mp[s[i]]=='A')
            mp[s[i]]=t[i];
        else if(mp[s[i]]!=t[i])
            {debug("No");return;}
        if(mp1[t[i]]=='A')
            mp1[t[i]]=s[i];
        else if(mp1[t[i]]!=s[i])
            {debug("No");return;}
    }
   debug("Yes");
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 916
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
#define foR for

// FHCまでにスタックオーバーフローの罠を解決する


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

    ll mod ;
    cin>>mod;
    int cnt = 1;
    bool used[mod+1]={};
    ll now = 7 % mod;
    while(now){
        cnt++;
        if(used[now]){
            cout << -1 << endl;
            return 0;
        }
        used[now] = 1;
        now *= 10;
        now += 7;
        now %= mod;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4608
package main

import (
  "fmt"
  "sort"
)

func main() {
  var N int
  fmt.Scan(&N)
  ws := make([]Work, N)
  for i := 0; i < N; i++ {
    var a,b int
    fmt.Scan(&a, &b)
    ws[i] = Work{a, b}
  }
  sort.Sort(ByB(ws))
  s := 0
  for _,w := range ws {
    if s+w.A > w.B {
      fmt.Println("No")
      return
    }
    s += w.A
  }
  fmt.Println("Yes")
}

type Work struct { A, B int }

type ByB []Work
func (a ByB) Len() int { return len(a) }
func (a ByB) Less(i, j int) bool { return a[i].B < a[j].B }
func (a ByB) Swap(i, j int) { a[i], a[j] = a[j], a[i] }



Measured memory_bytes: 7680
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

ll yowayowa = 0;

ll powo(ll x, ll y) {
	ll ans = 1;
	REP(i, 1, y) {
		ans *= x;
	}
	return ans;
}


ll const MAX = 30;
vector<vector<edge>> G(MAX);

vll u(30);

int main() {
	REP (i, 0, 24) {
		u[i] = powo(2, i - 1) - 1;
	}
	ll n;
	cin >> n;
	n--;
	ll goal = 1;
	ll m = 0;
	while (powo(2, goal) - 1 <= n) {
		G[goal].push_back({ goal + 1, powo(2,goal - 1) });
		G[goal].push_back({ goal + 1,0 });
		goal++;
		m += 2;
	}
	ll s = u[goal];
	while (s < n) {
		ll tmp = 0;
		while (u[tmp + 1] < n - s) {
			tmp++;
		}
		G[tmp].push_back({ goal, s + 1 });
		m++;
		s += u[tmp] + 1;
	}
	cout << goal << " " << m << endl;
	REP(i, 1, goal) {
		for (auto x : G[i]) {
			cout << i << " " << x.to << " " << x.len << endl;
		}
	}
	

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
int d[33][33];
int field[550][550];
signed main(){
    vector<int> cnt0(31,0);
    vector<int> cnt1(31,0);
    vector<int> cnt2(31,0);
    int n,c;cin >>n >> c;
    rep(i,c)rep(j,c){
        cin >> d[i][j];
        

    }
    rep(i,n)rep(j,n){
        cin >> field[i][j];
        field[i][j]--;
    }
    rep(i,n)rep(j,n){
        if((i+j+2)%3 == 0)cnt0[field[i][j]]++;
        if((i+j+2)%3 == 1)cnt1[field[i][j]]++;
        if((i+j+2)%3 == 2)cnt2[field[i][j]]++;

    }
    int ans = 1001001001;

    rep(i,c){
        rep(j,c){
            if(i == j)continue;
            rep(k,c){
                if(i == k ||j == k)continue;
                int ret = 0;
                rep(l,c){
                    ret += cnt0[l]*d[l][i];
                    ret += cnt1[l]*d[l][j];
                    ret += cnt2[l]*d[l][k];
                    

                }
                //trace(i,j,k,ret);
                ans = min(ans,ret);

            }

        }
    }
    cout << ans << endl;




    return 0;
}

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

int main() {
  int N, thousand, hundred, ten, one;
  cin >> N;
  one = N % 10;
  ten = (N % 100 - one)/10;
  hundred = (N % 1000 - ten - one)/100;
  thousand = (N - hundred - ten - one)/1000;
  if ((thousand == hundred && hundred == ten)||(hundred == ten && ten == one)) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 3640
/*
 * InsertionSort.cpp
 *
 *  Created on: 2014/07/25
 *      Author: WanWan1985
 */
#include <iostream>
#include <vector>
using namespace std;
 
void sort(vector<int>& a_rvecIntValue);
 
int main(void) {
 
    int iNum = 0;
    cin >> iNum;
    vector<int> vecIntValue;
    while (iNum) {
        int iIntValue = 0;
        cin >> iIntValue;
        vecIntValue.push_back(iIntValue);
        iNum--;
    }
 
    sort(vecIntValue);
 
    return 0;
}
 
void sort(vector<int>& a_rvecIntValue) {
 
    for (unsigned int i = 0; i < a_rvecIntValue.size(); i++) {
 
        if (i != 0) {
 
            int iIntValue = a_rvecIntValue.at(i);
            int j = i - 1;
            while ((j >= 0) && (a_rvecIntValue.at(j) > iIntValue)) {
                a_rvecIntValue.at(j+1) = a_rvecIntValue.at(j);
                j--;
            }
            a_rvecIntValue.at(j+1) = iIntValue;
        }
 
        for (unsigned int k = 0; k < a_rvecIntValue.size(); k++) {
            cout << a_rvecIntValue.at(k);
            if (k != a_rvecIntValue.size() - 1) {
                cout << " ";
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1220
N, M = map(int,input().split())
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for i in range(M)]

A.sort()
B.sort(reverse = True, key = lambda x: x[1])

cot = 0
add = 0

for b,c in B:
    cot += b
    if cot > N:
        add = N - cot + b
        A.extend([c] * add)
        break
    else:
        A.extend([c] * b)

print(sum(sorted(A, reverse = True)[:N]))

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

typedef pair<int, int> P;
const int N = 2e5;
const int INF = 1e18;

struct edge{ int to,cost; };
vector< edge > G[N];

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

  int n,m; cin >> n >> m;
  for(int i = 0; i < m; i++){
    int L,R,D; cin >> L >> R >> D;
    G[L].push_back({R,D});
    G[R].push_back({L,-D});
  }

  int d[N];
  fill(d,d+N,INF);
  queue<int> que;
  for(int i = 0; i < N; i++){
    if(G[i].empty() || d[i] < INF) continue;
    d[i] = 0; //基準にして考える
    que.push(i);
    while(!que.empty()){
      int from = que.front();
      for(int j = 0; j < G[from].size(); j++){
        int to = G[from][j].to;
        int cost = G[from][j].cost;
        if(d[to] < INF){
          if(d[to] != d[from] + cost){
            cout << "No" << endl;
            return 0;
          }
        }
        else {
          d[to] = d[from] + cost;
          que.push(to);
        }
      }
      que.pop();
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int C1 =0, C2 =0, C3 =0, C4 =0;
  vector<string> S(N);
  for(int i=0; i<N; i++) {
    cin >> S.at(i);
    if(S.at(i) == "AC") C1++;
    else if(S.at(i) == "WA") C2++;
    else if(S.at(i) == "TLE") C3++;
    else C4++;
  }
  
  cout <<"AC" << " " << "x" << " " << C1 << endl;
  cout <<"WA" << " " << "x" << " " << C2 << endl;
  cout <<"TLE" << " " << "x" << " " << C3 << endl;
  cout <<"RE" << " " << "x" << " " << C4 << endl;
}

Measured memory_bytes: 6436
N = int(input())
A = list(map(int,input().split()))

maxA,minA = max(A),min(A)
maxAi,minAi = -1,-1
sign = ""
M = []

for i in range(N):
    if A[i] == maxA:
        maxAi = i
        break
for i in range(N):
    if A[i] == minA:
        minAi = i
        break

if abs(maxA) >= abs(minA):
    A = list(map(lambda x: x+maxA, A))
    sign = "+"
else:
    A = list(map(lambda x: x+minA, A))
    sign = "-"

if sign == "+":
    for i in range(N):
        if i != maxAi:
            M.append((maxAi,i))
    M.append((maxAi,maxAi))
    for i in range(N-1):
        M.append((i,i+1))
elif sign == "-":
    for i in range(N):
        if i != minAi:
            M.append((minAi,i))
    M.append((minAi,minAi))
    for i in range(N-1):
        M.append((N-i-1,N-i-2))

L = len(M)
print(L)
for i in range(L):
    x,y = M[i]
    print(x+1,y+1)


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

int main(){
    int N;
    int t[100000], x[100000], y[100000];
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> t[i] >> x[i] >> y[i];
    }


    int distance;
    int difdistance;
    int count = 0;
    for (int i = 0; i < N; i++){
        if (i == 0){
            distance = abs(x[0] - 0) + abs(y[0] - 0);
            difdistance = t[0] - distance;
        }
        else{
            distance = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
            difdistance = t[i] - t[i - 1] - distance;
        }
        //cout << i << ": " << distance << endl;
        if ((difdistance < 0) || (difdistance % 2 == 1)){
            cout << "No" << endl;
            break;
        }
        count++;
    }
    if (count == N){
        cout << "Yes" << endl;
    }
    return 0;

}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int bottle1_max; 
int bottle1_amt;
int bottle2_amt;

int main() {
    cin >> bottle1_max >> bottle1_amt >> bottle2_amt;

    if (bottle1_amt + bottle2_amt < bottle1_max){
        cout << 0;
    }

    else{
        cout << bottle1_amt + bottle2_amt - bottle1_max;
    }

    return 0;
}


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

#define vi vector<int>
#define vul vector<ull>

#define lp(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define loopd(i,a,n) for(i=a;i>n;i--)
#define MAX 1000000007
        
vul jump; 
vi arr;
int k,n;

void dp(int i){
  int j;
  ull a;
  if(i>=0){
    jump[i]=MAX;
    loop(j,1,k+1){
      if(i+j>=n){
        break;
      }
      a = jump[i+j] + abs(arr[i+j] - arr[i]);
   	  jump[i] = min(a,jump[i]);
    }
    dp(i-1);
  }
}  

int main(){
  int i;
  cin>>n>>k;
  arr.resize(n);
  jump.resize(n);
  lp(i,n)
    cin>>arr[i];
  jump[n-1]=0;
  if(n>=2)	dp(n-2); 
  cout<<jump[0];
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <utility>
 
using namespace std;
using llong = long long;
 
llong a[50];
vector<pair<int,int>> op;
int main(){
  int N;
  cin >> N;
  llong maxa = -1;
  int maxi;
  for(int i=0;i<N;++i){
    cin >> a[i];
    if( abs(a[i]) > maxa ){
      maxa = abs(a[i]);
      maxi = i;
    }
  }
 
  for(int i=0;i<N;++i){
    if(maxi != i){
      op.emplace_back(maxi,i);
      a[i] += maxa;
    }
  }
 
  if(a[maxi] < 0){
    for(int i=N-2;i>=0;--i){
      op.emplace_back(i+1,i);
      a[i] += a[i+1];
    }
  }else{
    for(int i=1;i<N;++i){
      op.emplace_back(i-1,i);
      a[i] += a[i-1];
    }
  }
 
  cout << op.size() << endl;
  for(auto p:op){
    cout << p.first+1 << " " << p.second+1 << endl;
  }
 
  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = list(input())

# 初期の幸福度を計算
h = 0

for i in range(1, N):
    if S[i - 1] == S[i]:
        h += 1
        
# 基本的には１操作につき幸福度は2上がる

h += 2 * K

# 幸福度がN-1を超えることはない

if h > N - 1:
    h = N - 1
    
print(h)

Measured memory_bytes: 4024
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int INF = INT_MAX / 3;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> coin(n, 0);
	rep(i, m) cin >> coin[i];	
	vector<int> dp(n+1, INF); // n????????£?????´??????????°??????° 
	
	dp[0] = 0;
	for(int i = 0; i < m; ++i) {
		for(int j = coin[i]; j <= n; ++j) {	
			dp[j] = min(dp[j], dp[j-coin[i]] + 1);		
		}
	}

	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1524
#include<iostream>

int main(){
  int N,K,Y,X,s;

  std::cin >> N;
  std::cin >> K;
  std::cin >> X;
  std::cin >> Y;
  if (N <= K){
    s = N * X;
  }
  else {
    s = K * X + (N-K) * Y;
  }
  std::cout << s << std::endl;
}

Measured memory_bytes: 256
a=[]
i=2
k=0
a.append(int(input()))
for x in input().split(" "):
    a.append(int(x))

while i<=a[0]-1:
    if a[i]>=a[i-1] and a[i]>=a[i+1]:
        k+=0
    elif a[i]<=a[i-1] and a[i]<=a[i+1]:
        k+=0
    else:
        k+=1
    i+=1
print(k)

Measured memory_bytes: 3064
object Main extends App {
  import scala.io.StdIn._
  val n = readLong()
  var ans = 1000000000000L
  for(i <- 1L to(Math.sqrt(n).toLong)){
    if(n % i == 0){
      ans = Math.min(ans,i+n/i-2)
    }
  }
  println(ans)
}

Measured memory_bytes: 57016
#include <iostream>
#include <math.h>

int main(){
    int n;
    std::cin >> n;
    int x[n];
    int sum=0;
    int ans=0;
    for(int i=0;i<n;++i){
        std::cin >> x[i];
        sum+=x[i];
    }
    
    sum=sum/n;
    
    int ans1=0;
    int ans2=0;
    int ans3=0;
    
    for(int i=0;i<n;++i){
        ans1+=pow(x[i]-(sum-1),2);
    }
    for(int i=0;i<n;++i){
        ans2+=pow(x[i]-(sum),2);
    }
    for(int i=0;i<n;++i){
        ans3+=pow(x[i]-(sum+1),2);
    }
    
    if(ans1<=ans2){
        if(ans1<=ans3){
            ans=ans1;
        } else if(ans3<ans1){
            ans=ans3;
        }
    } else {
        if(ans2<=ans3){
            ans=ans2;
        } else if(ans3<ans2){
            ans=ans3;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
// date: June 11 2020
// author: Tibbarnit

#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll a,b;
int b1;
char ch;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>a>>b>>ch>>b1;
    b=b*100+b1;
    cout<<a*b/100;
    return 0;
}


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

using PP = pair<int, int>;
const long inf = 1e18;
int n, m, l, q;
long G[300][300];
long H[300][300];

void wf(long (*D)[300]) {
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
      }
    }
  }
}

int main() {
  cin >> n >> m >> l;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      G[i][j] = (i == j ? 0 : inf);
    }
  }
  
  for (int j = 0; j < m; ++j) {
    long a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    G[a][b] = min(G[a][b], c);
    G[b][a] = min(G[b][a], c);
  }
  
  wf(G);
  
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      H[i][j] = (G[i][j] <= l ? 1 : inf);
    }
  }
  
  wf(H);

  cin >> q;
  for (int k = 0; k < q; ++k) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    cout << (H[a][b] == inf ? -1 : H[a][b] - 1) << endl;
  }
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
ll ans;
int n, k, h[maxn];
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i) scanf("%d", &h[i]);
	sort(h + 1, h + n + 1, greater<int>());
	for(int i = k + 1; i <= n; ++i)
		ans += h[i];
	printf("%lld\n", ans);
	return 0;
}
	

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

#ifndef DUMP
#define DUMP(...) (void)0
#endif

using namespace std;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (auto&& e : p) cin >> e, --e;
  vector<int64_t> c(n);
  for (auto&& e : c) cin >> e;
  auto res = numeric_limits<int64_t>::min();
  for (int s = 0; s < n; ++s) {
    vector<int64_t> v;
    for (int i = s;; i = p[i]) {
      v.push_back(c[i]);
      if (p[i] == s) break;
    }
    int m = size(v);
    auto sum = accumulate(begin(v), end(v), 0LL);
    int64_t cur = 0;
    for (int r = 1; r <= m; ++r) {
      if (r > k) break;
      cur += v[r - 1];
      res = max(res, cur + (k - r) / m * max<int64_t>(sum, 0));
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		ll n; cin >> n;
		if(!n) break;
		vl k(n); rep(i,n) cin >> k[i];
		string s; cin >> s;
		ll m = s.size();
		rep(i,m){
			ll now = k[i%n];
			if(islower(s[i])){
				if(now <= s[i] - 'a') s[i] -= now;
				else if(now <= s[i] - 'a' + 26){
					s[i] = 'Z' - (now - (s[i] - 'a') - 1);
				}else{
					now -= s[i] - 'a' + 27;
					s[i] = 'z' - now;
				}
			}else{
				if(now <= s[i] - 'A') s[i] -= now;
				else if(now <= s[i] - 'A' + 26){
					s[i] = 'z' - (now - (s[i] - 'A') - 1);
				}else{
					now -= s[i] - 'A' + 27;
					s[i] = 'Z' - now;
				}
			}
		}
		cout << s << endl;
	}
}


Measured memory_bytes: 3200
#include<stdio.h>
#include<string.h>
int main(){
  int sum = 0, l, r, n;
  scanf("%d", &n);
  for(int i = 0; i < n; ++i){
    scanf("%d %d", &l, &r);
    sum += 1 + r - l;
  }
  printf("%d\n", sum);
  return 0;
}

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

long long mod = 1000000007;

int main(){
  long long N; cin >> N;
  long long A1[N], A2[N];
  long long res = 1;
  bool B1[N], B2[N];
  for (long i = 0; i < N; i++) cin >> A1[i];
  for (long i = 0; i < N; i++) cin >> A2[i];
  for (long i = 0; i < N; i++){
    B1[i] = 0; B2[i] = 0;
  }
  B1[0] = 1;
  B2[N-1] = 1;

  for (long i = 1; i < N; i++){
    if (A1[i] > A1[i-1]) B1[i] = 1;
  }
  for (long i = N-2; i >= 0; i--){
    if (A2[i] > A2[i+1]) B2[i] = 1;
  }


  for (long i = 0; i < N; i++){
    if (B1[i] && B2[i]){
      if (A1[i]!=A2[i]) {
        cout << 0 << endl;
        return 0;
      }
    } else if (!B1[i] && B2[i]){
      if (A1[i] < A2[i]) { cout << 0 << endl; return 0; }
    } else if (B1[i] && !B2[i]){
      if (A1[i] > A2[i]) { cout << 0 << endl; return 0; }
    } else res = res*min(A1[i], A2[i]);
    res = res%mod;
  }
  cout << res;
}


Measured memory_bytes: 2048
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array.Unboxed

f 'N' = 1
f 'W' = 2
f 'S' = 3
f 'E' = 4

solve a
    | and [n > 0, s > 0, w == 0, e == 0] = "Yes"
    | and [w > 0, e > 0, n == 0, s == 0] = "Yes"
    | and [n > 0, s > 0, w > 0, e > 0]   = "Yes"
    | otherwise                          = "No"
  where
    n = a ! 1
    w = a ! 2
    s = a ! 3
    e = a ! 4

main :: IO ()
main = do
    ss <- getLine
    let a = accumArray (+) 0 (1, 4) (zip (fmap f ss) (repeat 1)) :: UArray Int Int
    putStrLn $ solve a

Measured memory_bytes: 508
#include <stdio.h>

int main()
{
  int i,n,w,a,b,t;
  int data[30];

  scanf("%d",&w);
  scanf("%d",&n);
  for (i=0;i<w;i++){
    data[i]=i+1;
  }
  for (i=0;i<n;i++){
    scanf("%d,%d",&a,&b);
    t=data[a-1];
    data[a-1]=data[b-1];
    data[b-1]=t;
  }
  for (i=0;i<w;i++){
    printf("%d\n",data[i]);
  }
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int H, W, N, sr, sc; cin >> H >> W >> N >> sr >> sc;
    string S, T; cin >> S >> T;
    int a = 0, b = 0, c = 0, d = 0;
    for (int i = N-1; i >= 0; i--) {
        if (T[i] == 'L') b = max(b-1, 0);
        if (T[i] == 'R') a = max(a-1, 0);
        if (T[i] == 'U') d = max(d-1, 0);
        if (T[i] == 'D') c = max(c-1, 0);
        if (S[i] == 'L') a++;
        if (S[i] == 'R') b++;
        if (S[i] == 'U') c++;
        if (S[i] == 'D') d++;
        if (a + b >= W || c + d >= H) {
            cout << "NO\n";
            return 0;
        }
    }
    if (a >= sc || b >= (W - sc + 1) || c >= sr || d >= (H - sr + 1)) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }
    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
int main() {
    // 入力受け取り, 入次数も管理する
int n;
    cin >> n;
int count=0;
for(int i=1;i<=n;i++){


if(i%2==1){
int temp=0;

for(int j=1;j<=i;j++){
if(i%j==0)temp++;

}//f j

if(temp==8)count++;
}//if 

}//f i

cout << count;




}




Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
#define M max
int main() {
    int A,N,Max=0;
    cin >> N;
    long long goukei=0;
    for(int i=0;i<N;i++){
        cin >> A;
        goukei+=M(Max-A,0);
        Max=max(A,Max);
    }
    cout << goukei << endl;
    
}



Measured memory_bytes: 3608
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vl v(n);
  REP(i, n) cin >> v[i];
  REP(i, n) v[i]--;
  vl cnt(n, 0);
  FOR(i, 1, n) cnt[v[i]]++;
  ll ans = 0;
  REP(i, n) ans += cnt[i] * (cnt[i] - 1) / 2;
  cout << ans << endl;
  FOR(i, 1, n) {
    ans += cnt[v[i - 1]];
    cnt[v[i - 1]]++;
    cnt[v[i]]--;

    ans -= cnt[v[i]];
    cout << ans << endl;
  }
}


Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
using ll=long long;
const int M=1010;


int main(){
	string s[110];
	int y[110],m[110],d[110];

	for(int i=0;;i++){
		cin>>s[i];
		if(s[i][0]=='#')break;
		cin>>y[i]>>m[i]>>d[i];
	}

	for(int i=0;;i++){
		if(s[i][0]=='#')break;
		if(y[i]<31||(y[i]==31&&m[i]<5))
			cout<<"HEISEI "<<y[i]<<" "<<m[i]<<" "<<d[i]<<endl;
		else cout<<"? "<<y[i]-30<<" "<<m[i]<<" "<<d[i]<<endl;
	}

	return 0;
}


Measured memory_bytes: 3156
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	ll mon = 100;
	ll x;
	cin >> x;
	while(mon < x){
		ans ++;
		mon *= 1.01;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3612
program atcoder322_D
  integer(8),dimension(200000) :: A,B
  integer(8)::M
  read(5,*)N
  read(5,*)A(1:N)
  M=0
  do I=1,N
     B(A(I))=B(A(I))+1
  end do
  do I=1,N
     M=M+B(I)*(B(I)-1)/2
  end do
  do I=1,N
     write(6,*)M-(B(A(I))-1)
  end do
end program atcoder322_D

Measured memory_bytes: 8192
import qualified Data.Vector as V

main :: IO ()
main = do
  [h,w] <- map read . words <$> getLine
  t <- getTable h
  putStrLn $ if solve t h w then "Yes" else "No"

getTable :: Int -> IO Table
getTable h = V.replicateM h $ (V.fromList . map toBW) <$> getLine
  where toBW '#' = B
        toBW '.' = W
        toBW _ = error "!"

solve :: Table -> Int -> Int -> Bool
solve tbl h w = all check [(i,j) | j <- [0..(h-1)], i <- [0..(w-1)]]
  where
    get (i,j) = tbl V.! j V.! i
    around (x,y) | x == 0 && y == 0 = [(1,0),(0,1)]
                 | x == 0 && y == h-1 = [(x,y-1),(x+1,y)]
                 | x == w-1 && y == 0 = [(x-1,y),(x,y+1)]
                 | x == w-1 && y == h-1 = [(x-1,y),(x,y-1)]
                 | x == 0 = [(x,y-1),(x,y+1),(x+1,y)]
                 | x == w-1 = [(x,y-1),(x,y+1),(x-1,y)]
                 | y == 0 = [(x-1,y),(x+1,y),(x,y+1)]
                 | y == h-1 = [(x-1,y),(x+1,y),(x,y-1)]
                 | otherwise = [(x-1,y),(x+1,y),(x,y-1),(x,y+1)]
    check i | get i == W = True
            | otherwise = any (==B) [get n | n <- around i]

data BW = B | W deriving Eq

type Table = V.Vector (V.Vector BW)



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

int main(){
    int n, k;
    cin>>n>>k;
    vector<ll> v(n), dp(n);
    rep(i, n)
        cin>>v[i];
    dp[0] = 0;
    rep1(i, 1, n){
        dp[i] = LONG_LONG_MAX;
        rep1(j, 1, k+1)
            if(i>=j)
                dp[i] = min(dp[i], dp[i-j]+abs(v[i]-v[i-j]));
    }
    // rep(i, n) cout<<dp[i]<<" ";
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
h, w = map(int, input().split())

while not (h == 0 and w == 0):
    a = []
    for i in range(h):
        if i%2 == 0:
            a = ['#' if j%2 == 0 else '.' for j in range(w)]
        else:
            a = ['.' if j%2 == 0 else '#' for j in range(w)]

        print("".join(a))
    print("")

    h, w = map(int, input().split())


Measured memory_bytes: 5616
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

using llint = long long int;

void solve(void){
  std::string s, t;

  std::cin >> s >> t;

  int min_diff = 10000;
  for(int i=0; i<=s.size()-t.size(); i++){
    int diff = 0;
    for(int j=0; j<t.size(); j++){
      if(s[i+j]!=t[j]) diff++;
    }
    min_diff = std::min(min_diff, diff);
  }

  std::cout << min_diff << std::endl;
  
  return;
}
int main(void){
  solve();
  return 0;
}





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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()



struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    i64 N, M, x;
    cin >> N >> M >> x;
    vector<i64> C(N);
    vector<vector<i64>> A(N, vector<i64>(M));
    rep(i, N){
        cin >> C[i];
        rep(j, M) cin >> A[i][j];
    }
    i64 ans = -1;
    rep(i, (1LL)<<N){
        i64 p = 0;
        vector<i64> tmp(M);
        rep(j, N){
            if(i & ((1LL)<<j)){
                p += C[j];
                rep(k, M) tmp[k] += A[j][k];
            }
        }
        bool flag = true;
        rep(i, M) if(tmp[i] < x) flag = false;
        if(!flag) continue;
        if(ans == -1) ans = p;
        else ans = min(ans, p);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 2000023
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 1000000000000000
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return (ans.x+m)%m;
}
int fact[N];
void calfac(int n ){
fact[0] = 1;
for(int i = 1 ; i <= n+2; i++){
 fact[i] = (((fact[i-1]%mod)*(i%mod))%mod + mod)%mod;
}
 }
int calc(int n , int r){
 if(r > n)return 0;
 if(r == n)return 1;
 int ans = 1;
 ans = ((ans%mod)*(fact[n])%mod + mod)%mod;
 ans = ((ans%mod)*(mmInverse(fact[n-r] , mod)%mod) + mod)%mod;
 ans = ((ans%mod)*(mmInverse(fact[r] , mod)%mod) + mod)%mod;
 return (ans+mod)%mod;
}

int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int val;
cin>>val;
string str;
str = to_string(val);
int n = str.length();
int cnt = 1;
for(int i = 1 ; i <= n-1 ; i++){
       if(val - pow(26 , i )<= 0)break;
       val-=pow(26 , i);
       cnt++;
}
int x = val-1;
string ans="";
for(int i = 0 ; i < cnt ; i++){
        ans += 'a';
}
int k = ans.length()-1;
while(x > 0){
    int r = x%26;
    ans[k--] = ('a' + r);
    x= x/26;
}
//reverse(ans.begin() , ans.end());
cout<<ans<<endl;

}


Measured memory_bytes: 4140
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define CL(a,x) memset(a, x, sizeof(a))
const int N = 205;

int cap[N][N];
bool v[N];
int S,T,n,m;
int a[N>>1][N>>1],tmp[N];

int dfs(int x,int flow){
	if(v[x]) return 0;
	v[x]=true;
	if(x==T) return flow;
	int l,r;
	if(x<=n) l=n+1,r=2*n+1;
	else l=0,r=n;
	rep(y,l,r) if(cap[x][y] && !v[y]){
		int tmp=dfs(y,min(flow,cap[x][y]));
		if(tmp){
			cap[x][y]-=tmp;
			cap[y][x]+=tmp;
			return tmp;
		}
	}
	return 0;
}

int main(){
	scanf("%d%d",&n,&m);
	T = 0, S = 2 * n + 1;
	rep(i,1,n)rep(j,1,m){
		scanf("%d",a[i]+j);
		++cap[i][(a[i][j]-1)/m+n+1];
	}
	rep(k,1,m-1){
		rep(i,1,n) cap[S][i] = cap[i+n][T] = 1;
		for(CL(v,0);dfs(S,1e9);CL(v,0));
		rep(i,1,n)rep(j,n+1,2*n)if(cap[j][i]){
			cap[j][i] = 0;
			rep(x,k+1,m) if( (a[i][x]-1)/m+n+1 == j){
				swap(a[i][k], a[i][x]);
				break;
			}
		}
	}
	rep(i,1,n)rep(j,1,m)printf("%d%c",a[i][j],j==m?'\n':' ');
	rep(j,1,m){
		rep(i,1,n) tmp[i] = a[i][j];
		sort(tmp+1, tmp+n+1);
		rep(i,1,n) a[i][j] = tmp[i];
	}
	rep(i,1,n)rep(j,1,m)printf("%d%c",a[i][j],j==m?'\n':' ');
	return 0;
}

Measured memory_bytes: 512
using System;
					
public class Program
{
	
	// ABC129: B
	// Maybe: O(3N)
	public static void Main()
	{
		//Console.WriteLine("Hello World");
		
		var input = int.Parse(Console.ReadLine());
		var lead = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
		
		int[] weight = new int[input];
		int[] counterWeight = new int[input];
		weight[0] = lead[0];
		counterWeight[input-1] = lead[input-1];
		
		
		for(int i = 1; i < input-1; i++){
			weight[i] = weight[i-1] + lead[i];	
			counterWeight[input - 1 - i] = counterWeight[input - i] + lead[input - 1 -i];
		}
		
		int min = Math.Abs(weight[0] - counterWeight[1]);
		
		for(int i = 1; i < input-1; i++){
			min = Math.Min(min, Math.Abs(weight[i] - counterWeight[i+1]));
		}
						   
		Console.WriteLine(min);
		
		
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int sum[110],sum1[110];
int main()
{
    int n,a[110];
    int minn=1<<30;
    cin>>n;
    for(int i=1;i<=n;i++)   scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)   sum[i]=sum[i-1]+a[i];
    for(int i=n;i>=1;i--)   sum1[i]=sum1[i+1]+a[i];
    for(int i=1;i<=n;i++){
        minn=min(abs(sum1[i]-sum[i-1]),minn);
    }
    cout<<minn<<endl;
    return 0;
}


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

#define FOR(i,a,b) for(lint i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=2019;
int main(){
  lint L,R;
  cin>>L>>R;
  if(R-L>p){
    cout<<0<<endl;
    return 0;
  }
  lint ans=p;
  FOR(i,L,R)FOR(j,i+1,R+1){
    ans=min(ans,(i*j)%p);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char ymd[12];
    int ans[12] = {0};
    scanf("%s", ymd);
    
    if(ymd[5] == '0'){
        if(ymd[6] >= '5'){
            printf("TBD\n");
        }else {
            printf("Heisei\n");
        }
    }else {
        printf("TBD\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> d(n), c(n);
    for(int i = 0; i < n; i++)  cin >> d[i] >> c[i];
    vector<int> dp(200001, 1<<30);
    priority_queue<pair<int, int>> pq;
    pq.push({-0, 0});
    while(!pq.empty()){
        pair<int,int> p = pq.top(); pq.pop();
        int cost = -p.first, pos = p.second;
        if(cost >= dp[pos]) continue;
        dp[pos] = cost;
        if(pos == x)    break;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 2; j++){
                int next = pos + (2*j-1)*d[i];
                if(inRange(next, 0, 200001) && dp[next] > cost+c[i]){
                    pq.push({-(cost+c[i]), next});
                }
            }
        }
    }
    cout << (dp[x] == 1<<30 ? -1 : dp[x]) << endl;
    return 0;
}


Measured memory_bytes: 20116
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	string s;
	cin >> s;
	int N=s.size();
	long long ans = 0;
	for (int i = 0; i < (1 << N-1); i++) {
		long long x = 0;
		long long a = s[0] - '0';
		for (int j = 0; j < N - 1; j++) {
			if (i&(1 << j)) {
				x += a;
				a = 0;
			}
			a = a * 10 + s[j + 1] - '0';
		}
		x += a;
		ans += x;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


bool enough(ll t, ll a, ll b, VL &v){
    ll add_cnt = 0;
    REP(i, v.size()){
        if(v[i] > b * t) {
            add_cnt += ((v[i] - b * t) + (a - b) - 1) / (a - b);
        }
    }
    return add_cnt <= t;
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    VL h;
    ll h_max = 0;
    REP(i, n){
        ll temp;
        cin >> temp;
        h.push_back(temp);
        h_max = max(h_max, temp);
    }

    // 二分探索
    ll min_t = 1;
    ll max_t = (h_max + b - 1) / b;
    while(max_t - min_t > 1){
        ll mid_t = (max_t + min_t) / 2;
        if(enough(mid_t, a, b, h) == true){
            max_t = mid_t;
        }else{
            min_t = mid_t;
        }
    }
    cout << max_t << "\n";
    return 0;
}


Measured memory_bytes: 1400
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#define MN 100005
#define INF 1000000007
#define IMP 2147483647
#define pp pair<int,int>
using namespace std;
vector<pp> rel[MN];
int n,m;
int w[MN];
bool chk[MN];
bool ans;
void dfs(int x) {
	chk[x] = true;
	if (w[x] == IMP) w[x] = 0;
	for (auto next : rel[x]) {
		int y=next.first, d=next.second;
		if (w[y] != IMP && w[y] != w[x] + d) ans = false;
		if (!chk[y]) {
			w[y] = w[x] + d;
			dfs(y);
		}
	}
}
int main() {
	scanf("%d%d", &n, &m);
	ans = true;
	int i;
	for (i = 1; i <= n; i++) w[i] = IMP;
	for (i = 1; i <= m; i++) {
		int l, r, d;
		scanf("%d%d%d", &l, &r, &d);
		rel[l].push_back({ r,d });
		rel[r].push_back({ l,-d });
	}
	for (i = 1; i <= n; i++) {
		if (!chk[i]) dfs(i);
	}
	if (ans) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 11136
len_arr = int(input())
arr = [int(x) for x in input().split(' ')]
increasing = range(1, len_arr+1)

rep_inc = 0

for i, inc in zip(arr, increasing):
    if i != inc:
        rep_inc += 1

if rep_inc == 0 or rep_inc == 2:
    print("YES")
else:
    print("NO")

exit(0)


Measured memory_bytes: 3060
n=int(input())
h=[int(k) for k in input().split()]
dp=[0,abs(h[0]-h[1])]
for i in range(2,n):
    dp.append(min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]))
print(dp[n-1])

Measured memory_bytes: 55528
#include <iostream> 
#include <cstring>
#include <algorithm>
using namespace std;
long long a[51];


int main(){
	long long k;
	cin >> k;
	cout << "50\n";
	long long k1 = k / 50;
	long long k2 = k % 50;
	for (int i = 1; i <= 50; i++) a[i] = 49 + k1;
	for (int i = 1; i <= k2; i++) a[i] += 50 - k2 + 1;
	for (int i = k2 + 1; i <= 50; i++) a[i] -= k2;
	for (int i = 1; i <= 50; i++) cout << a[i] << " ";
	
	return 0;	
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int h[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	sort(h, h + n);
	int mi = 1e9;
	for (int i = 0; i < n - k + 1; i++) {
		mi = min(mi, h[i + k - 1] - h[i]);
	}
	cout << mi << '\n';
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int dist[30][30][30][30];
int h,w,x,y,nx,ny;
char s[30][30];
queue<pair<int,int> > q;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>w;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>s[i][j];
	memset(dist,63,sizeof(dist));
	int res=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(s[i][j]=='#')
				continue;
			q.push(make_pair(i,j));
			dist[i][j][i][j]=0;
			while(q.size()){
				x=q.front().first;
				y=q.front().second;
				q.pop();
				for(int k=0;k<4;k++){
					nx=x+dx[k];
					ny=y+dy[k];
					if(nx>=1&&nx<=h&&ny>=1&&ny<=w){
						if(s[nx][ny]=='.'){
							if(dist[i][j][nx][ny]>dist[i][j][x][y]+1){
								dist[i][j][nx][ny]=dist[i][j][x][y]+1;
								q.push(make_pair(nx,ny));
							}
						}
					} 
				}
			}
			for(int k=1;k<=h;k++)
				for(int l=1;l<=h;l++)
					if(s[k][l]=='.')
						res=max(res,dist[i][j][k][l]);
		}
	}
	cout<<res<<endl;
	return 0;
}


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

int main() {
    int N, Q; cin >> N >> Q;
    fenwick_tree<long long> bit(N+1);
    for (int i=1;i<=N;i++) {
        int a; cin >> a;
        bit.add(i, a);
    }
    for (int q=0; q<Q; q++) {
        int d, l, r; 
		cin >> d >> l >> r;
        if (d == 0) {
            bit.add(l+1, r);
        } else {
            cout << bit.sum(l+1, r+1) << "\n";
        }
    }
}


Measured memory_bytes: 8220
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
using namespace std;
int n,a,b;
int main(){
    cin>>n>>a>>b;
    if((b-a)&1)puts("Borys");
    else puts("Alice");
	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 7;
char s[maxx];

int main() {
	scanf("%s", s);
	int l = strlen(s);
	for(int i = 0; i < l; i++) if(!(i & 1)) putchar(s[i]);
	putchar('\n');
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdlib.h>

using namespace std;

int main()
{
	int n,w;
	cin >> n >> w;
	vector <pair <int, int> > all(n);
	for (int i = 0; i < n; i++)
	{
		cin >> all[i].first >> all[i].second;
	}
	sort(all.begin(), all.end());
	vector < vector <unsigned long long> > dp(n + 1, vector <unsigned long long> (w + 1, 0));
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= w; j++)
		{
			if (i == 0 || j == 0)
				dp[i][j] = 0;
			else
			{
				if (j >= all[i - 1].first)
					dp[i][j] = max(all[i - 1].second + dp[i - 1][j - all[i -1].first], dp[i - 1][j]);
				else
					dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout << dp[n][w];
}

Measured memory_bytes: 80256
N = int(input())
H = [int(x) for x in input().split()]

max = 0
ans = 0
for i in range(1,N):
    #print(i)
    if(H[i]<=H[i-1]):
        ans += 1
        if(ans>max):
            max += 1
    else:
        ans = 0
print(max)

Measured memory_bytes: 14252
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  cout << (min(min(a, b), c) + min(d, e) - 50) << '\n';

  return 0;
}

Measured memory_bytes: 1192