akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static int count = 0;
	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		
		int n = Integer.parseInt(br.readLine());
		String[] sready = (br.readLine()).split(" ");
		int[] s = new int[n];
		for (int i = 0; i < n; i++)
			s[i] = Integer.parseInt(sready[i]);
		
		int q = Integer.parseInt(br.readLine());
		String[] tready = (br.readLine()).split(" ");
		int[] t = new int[q];
		for (int i = 0; i < q; i++)
			t[i] = Integer.parseInt(tready[i]);
		
		for (int i = 0; i < q; i++)
			doBinarySearch(s, t[i]);
		
		pw.println(count);
		pw.close();
	}
	
	public static void doBinarySearch(int[] s, int x) {
		int index1 = 0;
		int index2 = s.length - 1;
		if (x < s[index1])
			return;
		else if (x > s[index2])
			return;
		
		int point = (index2 - index1) / 2;
		do {
			if (s[point] == x) {
				count++;
				break;
			}
			else if (s[point] > x)
				index2 = point;
			else
				index1 = point;
			point = index1 + (index2 - index1) / 2;
		} while (index2 - index1 > 1);
		if (index2 - index1 ==1) {
			if (s[index1] == x)
				count++;
			else if (s[index2] == x)
				count++;
		}
	}
}

Measured memory_bytes: 47420
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <map>

using namespace std;

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

    map<string, int> S;
    int cmd, x;
    string key;
    while (q--)
    {
        cin >> cmd;
        if (cmd == 0)
        {
            cin >> key >> x;
            S[key] = x;
            // cout << S.size() << endl;
        }
        else if (cmd == 1)
        {
            cin >> key;
            // cout << (S.find(x) != S.end()) << endl;
            cout << S[key] << endl;
        }
        // else if (cmd == 2)
        // {
        //     cin >> x;
        //     S.erase(x);
        //     // remove(S.begin(), S.end(), x);
        // }
        // else
        // {
            // cin >> L >> R;
            // map<int>::iterator it1 = S.lower_bound(L), it2 = S.upper_bound(R);
            // while (it1 != it2)
            // {
            //     cout << *it1 << endl;
            //     it1++;
            // }

        // }
        
        
    }
}


Measured memory_bytes: 27888
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=310;
int n,m,a[maxn][maxn],nn[maxn],tot[maxn],ans,nans,npos;
bool ok[maxn];

int aa;char cc;
int read() {
	aa=0;cc=getchar();
	while(cc<'0'||cc>'9') cc=getchar();
	while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
	return aa;
}

int main() {
	n=read();m=read();ans=n;
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) a[i][j]=read();
	for(int i=1;i<=n;++i) nn[i]=1;
	for(int i=1;i<=m;++i) {
		memset(tot,0,sizeof(tot));nans=0;
		for(int j=1;j<=n;++j) tot[a[j][nn[j]]]++;
		for(int j=1;j<=m;++j) if(tot[j]>nans) nans=tot[j],npos=j;
		ans=min(ans,nans); ok[npos]=1;
		for(int j=1;j<=n;++j) while(ok[a[j][nn[j]]]) nn[j]++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		String[] b = a.split("");
		
		int c=a.length();
		
		if(c==3){
			String str=b[0];
			b[0]=b[2];
			b[2]=str;
		}
		
		for(int i=0;i<c;i++){		
			System.out.print(b[i]);
		} 
	}

}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	if(n>=2 && m>=2){
		cout<<(n-2)*(m-2)<<endl;
	}else if(n>=2 || m>=2){
		cout<<max(n,m)-2<<endl;
	}else{
		cout<<1<<endl;
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    ld A, B, H, M;
    cin >> A >> B >> H >> M;
    ld a, b;
    ld pi = 3.14159265358979;
    b = 2*pi*M/60;
    a = (2*pi*H/12) + (pi/6)*(M/60);
    ld the = abs(b-a);
    ld ans = A*A+B*B-2*A*B*cos(the);
    cout << sp(15) << sqrt(ans) << endl;
}

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

const int N = 5e3 + 9, M = 205, INF = 0x3f3f3f3f;

using ll = long long;
int n, m, nxt[M][N], b[M][N], s[N], t, op[N];
ll a[N], sum, ans;
deque<int>Q[M];

int main () {
	scanf("%d%d", &n, &m);
	for (int i = 1; i < n; ++i) scanf("%d", &op[i]);
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) scanf("%d", &b[j][i]);
	for (int i = 1; i <= m; ++i) {
		b[i][n + 1] = INF;
		s[t = 1] = n + 1;
		for (int j = n; j; --j) {
			while (b[i][j] >= b[i][s[t]]) --t;
			nxt[i][j] = s[t];
			s[++t] = j;
		}
	}
	for (int i = n; i; --i) a[i] = -op[i - 1];
	for (int i = 1; i <= m; ++i) Q[i].push_back(n + 1);
	for (int i = 1, j, k, l, r; i <= n; ++i) {
		a[i] += op[i - 1];
		for (j = 1; j <= m; ++j) {
			while (Q[j].front() < i) k = Q[j].front(), Q[j].pop_front();
			if (Q[j].front() != n + 1) a[Q[j].front()] += b[j][k];
			for (l = i, r = Q[j].front(), t = 0; l && l < r; l = nxt[j][l]) s[++t] = l;
			while (t) {
				if (Q[j].front() != n + 1) a[Q[j].front()] -= b[j][s[t]];
				a[s[t]] += b[j][s[t]];
				Q[j].push_front(s[t--]);
			}
//			printf("It's %d %d : ", i, j); for (auto v : Q[j]) printf("%d%c", v, v == n + 1 ? '\n' : ' ');
		}
		for (sum = 0, j = i; j <= n; ++j) {
			sum += a[j];
			if (sum > ans) ans = sum;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8448
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
   	int n = sc.nextInt();
    String shops[] = new String[n];
    String shops2[] = new String[n];
    String names[] = new String[n];
    String points[] = new String[n];
    String[] stack;
    String[] stack2;
    List<Integer> pList;
    Map<String, Integer> rank = new HashMap<String, Integer>();
    int start;
    int end;
    
    for(int i = 0;i < n;i++){
      names[i] = sc.next();
      points[i] = sc.next();
      shops[i] = names[i] + " " + points[i] + " ";
      shops2[i] = shops[i];
      rank.put(names[i] + " " + points[i] + " ",i + 1);
    }
    
    Arrays.sort(shops2);
    
    stack = shops2[0].split(" ");
    names[0] = stack[0];
    pList =  new ArrayList<Integer>();
    pList.add(Integer.parseInt(stack[1]));
    start = 0;
    
    for(int i = 1;i < n; i++) {
      	stack2 = shops2[i].split(" ");
      	names[i] = stack2[0];
    	if(stack[0].equals(stack2[0])){
        	pList.add(Integer.parseInt(stack2[1]));
          	if(i == n - 1){
            	Collections.sort(pList);
          		for(int j = 0; j < i + 1 - start;j++) {
            		points[start + j] = String.valueOf(pList.get(i - start -j));           
                }
            }
        } else {
          Collections.sort(pList);
          for(int j = 0; j < i - start;j++) points[start + j] = String.valueOf(pList.get(i - start -j -1));
          start = i;
          pList =  new ArrayList<Integer>();
          pList.add(Integer.parseInt(stack2[1]));
          if(i == n - 1) points[i] = stack2[1];
        } 
      	stack = stack2;
    }
	
    for(int i = 0;i < n;i++){
      System.out.println(rank.get(names[i] + " " + points[i] + " "));
    }
    
  }
}


Measured memory_bytes: 39396
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int m,d;

int main(void){
	scanf("%d%d",&m,&d);
	int ans=0;
	for(int i=1;i<=m;i++){
		for(int j=22;j<=d;j++){
			int a=j%10;
			int b=j/10;
			if(a<=1)continue;
			if(a*b==i){
				ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


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


int main() {
  int x;
  cin >> x;
  if (x == 1) cout << "Hello World" << endl;
  else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
}

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

int main() {
    string s;
    int n;
    vector<int> sum;
    while(cin >> s, s != "0"){
        n = s.size();
        sum.assign(n+1, 0);
        for(int i=0;i<n;i++){
            if(i%2) sum[i+1] += s[i] - '0';
            else sum[i+1] -= s[i] - '0';
            sum[i+1] += sum[i];
        }
        int ans = 0, cnt[11]{};
        cnt[0] = 1;
        s.push_back('#');
        for(int i=0;i<n;i++){
            int m = (sum[i+1]%11+11)%11;
            ans += cnt[m];
            if(s[i+1] != '0') cnt[m]++;
        }
        cout << ans << endl;
    }
    return 0;
}



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

using namespace std;

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  std::swap(A, B);
  std::swap(A, C);
  std::cout << A << " "
            << B << " "
            << C;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n,m;
  int one=1;
  cin>>n;
  string s;
  pair<int,string> b;
  vector<pair<int,string> > a;
  rep(i,n){
    cin>>s;
    b=make_pair(one,s);
    if(i==0) a.push_back(b);
    else{
      rep(j,a.size()){
	if(a[j].second==s){a[j].first++;break;}
	else if(j==a.size()-1){a.push_back(b);break;}
      }
    }
  }
 
  cin>>m;
  rep(i,m){
    cin>>s;
    rep(j,a.size()){
      if(a[j].second==s) a[j].first--;
    }
  }
  sort(a.begin(),a.end());
  int ans;
  
  ans=a[a.size()-1].first;
  //cout<<a.size()<<endl;
  if(ans<0) ans=0;
  cout<<ans<<endl;
  return 0;
}













Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;
  bool operator < (const Puzzle &p) const {
    for (int i = 0; i < N2; i++) {
      if (f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};

bool istarget(Puzzle p){
  for(int i=0;i<N2;i++){
    if(p.f[i]!=(i+1)) return false;
  }
  return true;
}

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle,bool> V;
  Puzzle u,v;
  s.path="";
  Q.push(s);
  V[s]=true;
  while(!Q.empty()){
    u=Q.front(); Q.pop();
    if(istarget(u)) return u.path;
    int sx=u.space/N;
    int sy=u.space%N;
    for(int i=0;i<4;i++){
      int tx=sx+dx[i];
      int ty=sy+dy[i];
      if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
      v=u;
      swap(v.f[u.space],v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
	V[v]=true;
	v.path+=dir[i];
	Q.push(v);
      }
    }
  }
  return "unsolvable";
}

int main(){
  Puzzle in;
  for(int i=0;i<N2;i++){
    cin>>in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  string ans=bfs(in);
  cout<<ans.size()<<endl;
  return 0;
}
  



Measured memory_bytes: 30616
typedef char Bool;
#define true 39
#define false 0 
typedef long long int64;
typedef unsigned long long uint64;
typedef int int32;
typedef unsigned int uint32;
typedef unsigned char byte;
#pragma warning(disable:4996)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <malloc.h>

int upsortcheck(const void* a, const void* b)
{
	if (*(int*)a > *(int*)b)
	{
		return 1;
	}
	else if (*(int*)a < *(int*)b)
	{
		return -1;
	}
	else
	{
		return 1;
	}
}

int main()
{
	int k, n;
	scanf("%d %d", &n, &k);
	int* p = (int*)malloc(sizeof(int) * n);

	//int p[1000];
	
	for (int i = 0; i != n; i++)
	{
		scanf("%d", &p[i]);
	}

	qsort(p, n, sizeof(int), upsortcheck);

	int a = 0;
	for (int i = 0; i != k; i++)
	{
		a += p[i];
	}
	printf("%d", a);

	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  map<int,int> mp;
  for(int i=2;i<=n;i++){
    int j=2,k=i;
    while(k>1){
      if(k%j==0){
        k/=j;mp[j]++;
      }else{
        j++;
      }
    }
  }
  long ans=1;
  for(auto c:mp){
    ans*=(c.second+1);
    ans%=1000000007;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
c = readlines.map{|line| line.chomp.split.map(&:to_i)}
b = c[0].map{|i| i - c[0][0]}
a = (0..2).map{|j| c[j][0] - b[0]}
d = (0..2).map{|i| (0..2).map{|j| a[i] + b[j]}}

puts c == d ? :Yes : :No

Measured memory_bytes: 3836
import sys

def compoundInterest(x, i, n):
    if n == 0:
        return x

    ans = int(x * (1 + i))
    hasu = ans % 1000
    if hasu != 0:
        ans -= hasu
        ans += 1000
    return compoundInterest(ans, i, n-1)

if __name__ == "__main__":
    n = int(input())
    ans = compoundInterest(100000, 0.05, n)
    print (ans)

Measured memory_bytes: 7736
import sys
di = {1:".,!? ",2 :"abc",3:"def",4:"ghi",5:"jkl",6:"mno",7:"pqrs",8:"tuv",9:"wxyz"}
b = input()

for j in range(b):
    a = raw_input()
    count = 0
    le = 999
    for letter in a:
        if(letter == "0"):
            if(le == 999):
                pass
            else:
                sys.stdout.write(di[le][(count-1)%len(di[le])])
                count = 0
                le = 999
        else:
            le = int(letter)
            count += 1
    print ""

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
   int n;
   cin >> n;
   vector<int>x(n),y(n),d;
   rep(i, 0, n)cin >> x[i] >> y[i];
   rep(i, 0, n){
       rep(j, 0, n){
           int dist = (y[i]-y[j])*(y[i]-y[j])+(x[i]-x[j])*(x[i]-x[j]);
           d.push_back(dist);
       }
   }
   double sum = 0;
   rep(i, 0, d.size()){
       sum += sqrt((double)(d[i]));
   }
   cout << fixed << setprecision(10) << sum/(double)(n) << endl;
}

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

int main(){
  long long  n, m, x[100009];
  long long int sm=0;
  vector<long long> v1, v2;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> x[i];
    v1.push_back(x[i]);
  }
  if(n>=m){
    cout << 0 << endl;
  }
  else{
    sort(v1.begin(), v1.end());
    for(int i=1;i<m;i++){
      v2.push_back(v1[i] - v1[i-1]);
      sm += v1[i] -v1[i-1];
    }
    sort(v2.begin(), v2.end(), greater<long long>());
    for(int i=0;i<n-1;i++){
      sm-=v2[i];
    }
    cout << sm << endl;
  }
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>
#define lint int64_t

int main(){
    string X;
    cin >> X;
   
    stack<int> s;
    rep(i,X.size()){
        
        if(!s.empty() && s.top() == 'S' && X.at(i) == 'T'){
            s.pop();
        }else{
            s.push(X.at(i));
        }        
    }

    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 1284
#include<iostream>
using namespace std;
int main(){
  int a,b,k,cnt=0,i;
  cin >> a >> b >> k;
  for(i=max(a,b);;i--){
    if(a%i==0&&b%i==0){
      cnt++;
      if(cnt==k) break;
    }
  }
  cout << i << endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

bool pcheck(int n) {
    int x = sqrt(n);
    for (int i = 2; i <= x; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    for (int i = n; i <= 2 * n; i++) {
        if (pcheck(i)) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    n, k = map(int, input().split())
    table = [1]*n
    for i in range(k):
        d = int(input())
        a = list(map(int, input().split()))
        for j in range(d):
            table[a[j]-1] = 0
    print(sum(table))


main()


Measured memory_bytes: 67608
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	long long count=0;
	cin>>n>>k;
	long long *a=new long long[n];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	if(n<=k)cout<<0;
	else{
		for(int i=0;i<n-k;i++)count+=a[i];
		cout<<count;
	}
	delete a;
	return 0;
}

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

using namespace std;

int main(){
string s,t;

cin>>s;
cin>>t;

sort(s.begin(),s.end());
sort(t.begin(),t.end(),greater<int>());

cout<<((s.compare(t) < 0) ? "Yes" :"No")<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const LL mo=1e9+7;
LL power(LL a,LL b)
{
	LL cnt=1;
	while(b)
	{
		if(b&1)
		{
			cnt*=a;
			cnt%=mo;
		}
		a*=a;
		a%=mo;
		b>>=1;
	}
	return cnt;
}
LL solve(LL a)
{
	return ((power(10,a)+mo-power(9,a))%mo-(power(9,a)+mo-power(8,a))%mo+mo)%mo;
}
int main()
{
	LL a;
	cin >> a;
	cout << solve(a);
}

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N, K = Scanner.map_int()
    A = Scanner.map_int()
    print(Math.roundUp(N-1, (K - 1)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 53068
fun main(args: Array<String>) {
    val k = readLine()!!.toInt()
    val range = readLine()!!.split(" ").map { it.toInt() }
    val a = range[0] // min
    val b = range[1] // max

    if(k > b) {
        print("NG")
        return
    }

    if(a%k == 0 || b%k ==0) {
        print("OK")
        return
    }

    var minMultiplyNumber = if(a%k == 0)  a/k else (a/k) + 1
    val maxMultipleNumber = if(b%k == 0)  b/k else (b/k)

    val result = IntRange(minMultiplyNumber * k , maxMultipleNumber * k).firstOrNull{it % k == 0}
    if(result != null) print("OK") else print("NG")
}


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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, c; cin >> n >> c;

  vector<pair<P, int>> m(n);
  REP(i, n) {
    cin >> m[i].fi.fi >> m[i].fi.se >> m[i].se;
  }
  sort(ALL(m));

  vector<P> ans(1);
  ans[0] = P(m[0].fi.se, m[0].se);
  FOR(i, 1, n) {
    // cout << i << ":" << SZ(ans) << endl;
    REP(j, SZ(ans)) {
      if(ans[j].se == m[i].se) {
        if(ans[j].fi <= m[i].fi.fi) {
          ans[j].fi = m[i].fi.se;
          break;
        }
      } else {
        if(ans[j].fi <= m[i].fi.fi - 0.5) {
          ans[j].fi = m[i].fi.se;
          ans[j].se = m[i].se;
          break;
        }
      }
      if(j == SZ(ans) - 1) {
        ans.pb(P(m[i].fi.se, m[i].se));
        break;
      }
    }
  }

  cout << SZ(ans) << endl;
}


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

int main(void) {
    int K;
    string S;
    cin >> K >> S;
    int size = S.size();
    if (size <= K) {
        cout << S << "\n";
    } else {
        for (int i = 0; i < K; i++) {
            cout << S[i];
        }
        printf("...\n");
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N];
int main()
{
    long long n;
    cin>>n;
    long long tmp=1;
    long long ans=0;
    while(n>0)
    {
        ans+=tmp;
        tmp=tmp*2;
        n=n/2;
    }
    cout<<ans<<endl;
    //cout << "Hello world!" << endl;
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int N, M;
    cin >> N >> M;

    int64_t ans = 0;

    multimap<int64_t, int64_t> m;
    int64_t a, b;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        m.emplace(a, b);
    }

    for (auto p: m) {
        int64_t a = p.first;
        int64_t b = p.second;

        int64_t sub = M - b;
        if (sub <= 0) {
            //  もう買えない
            ans += (a * M);
            break;
        } else {
            //  まだ買える
            ans += (a * b);
            M = M - b;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
fn main() {
    let n: usize = read();
    let a: Vec<usize> = read_vec();
    let b: Vec<usize> = read_vec();
    let c: Vec<usize> = read_vec();
    let mut ans = 0;

    for i in 0..n - 1 {
        if a[i] + 1 == a[i + 1] {
            ans += b[a[i] - 1] + c[a[i] - 1];
        } else {
            ans += b[a[i] - 1];
        }
    }
    ans += b[a[n - 1] - 1];
    println!("{}", ans);
}





//**********************************************************************************************************************************************//

// 標準入力から一行を読み取り、指定の型に変換する関数
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec2<T: std::str::FromStr>(n: u64) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

// 10進数での各桁の和
pub fn sum_dights(x: isize) -> isize {
    if x % 10 == 0 {
        return 0
    }
    let m = x % 10;
    m + sum_dights((x - m) / 10)
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int N = 1e3+5,M = 1e6+5,MAXN = 1e7+5;
int n,x,mx,ccnt,S,T,pri[MAXN];
char is_not[MAXN],ty[MAXN];
il Init(){
	is_not[1]=1;
	for(ri i=2;i<=MAXN-5;++i){
		if(!is_not[i]) pri[++ccnt]=i;
		for(ri j=1;j<=ccnt&&i*pri[j]<=MAXN-5;++j){
			is_not[i*pri[j]]=1;
			if(i%pri[j]==0) break;
		}
	}
}
int num_edge=-1,head[N],cur[N],dis[N],cntL,cntR,L[N],R[N];
struct Edge{ int next,to,w; }edge[M];
il add_edge(int u,int v,int w){
	edge[++num_edge]=(Edge){ head[u],v,w },head[u]=num_edge;
	edge[++num_edge]=(Edge){ head[v],u,0 },head[v]=num_edge;
}
inl bool BFS(int s,int t){
	for(ri i=s;i<=t;++i) dis[i]=0;
	queue<int> q;q.push(s),dis[s]=1;
	while(!q.empty()){
		int pos=q.front();q.pop();
		for(ri i=head[pos];i!=-1;i=edge[i].next)
			if(edge[i].w>0&&!dis[edge[i].to]){
				dis[edge[i].to]=dis[pos]+1;
				if(edge[i].to==t) return true;
				q.push(edge[i].to);
			}
	}
	return false;
}
it DFS(int now,int t,int flow){
	if(now==t) return flow;
	int s=0,k;
	for(ri &i=cur[now];i!=-1;i=edge[i].next) if(edge[i].w>0&&dis[edge[i].to]==dis[now]+1){
		k=DFS(edge[i].to,t,min(flow-s,edge[i].w));
		s+=k,edge[i].w-=k,edge[i^1].w+=k;
		if(s==flow) break;
	}
	if(!s) dis[now]=0;
	return s;
}
it Dinic(int s,int t){
	int res=0;
	while(BFS(s,t)){
		for(ri i=s;i<=t;++i) cur[i]=head[i];
		res+=DFS(s,t,INF);
	}
	return res;
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),Init(),del(head,-1);
	for(ri i=1;i<=n;++i) read(x),ty[x]=1,mx=max(mx,x+1);
	for(ri i=mx;i>=1;--i) ty[i]=ty[i]^ty[i-1];
	for(ri i=1;i<=mx;++i){
		if(!ty[i]) continue;
		if(i&1) L[++cntL]=i;
		else R[++cntR]=i;
	}
	T=cntL+cntR+1;
	for(ri i=1;i<=cntL;++i) add_edge(S,i,1);
	for(ri i=1;i<=cntR;++i) add_edge(i+cntL,T,1);
	for(ri i=1;i<=cntL;++i) for(ri j=1;j<=cntR;++j)
		if(!is_not[abs(L[i]-R[j])]) add_edge(i,j+cntL,1);
	int mx_flow=Dinic(S,T),ans=mx_flow;
	ans+=(cntL-mx_flow)/2*2+(cntR-mx_flow)/2*2;
	ans+=((cntL-mx_flow)&1)*3;
	print(ans);
	return 0;
}

Measured memory_bytes: 24832
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}




Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 1234567890;

int D;
int x[100000];

const int B = 50;
const int SZ = 2000;

// default,sorted
vector<int> d[B],s[B];

int f(int l, int r, int p, int q)
{
    int ret = r-l+1;
    for(int i=l; i<=r; ++i)if(p<=x[i] && x[i]<=q) --ret;
    return ret;
}

int g(int bid, int p, int q)
{
    int lidx = lower_bound(all(s[bid]), p) - s[bid].begin();
    int ridx = upper_bound(all(s[bid]), q) - s[bid].begin();
    int ct = ridx - lidx;
    return SZ - ct;
}

int query(int l, int r, int e)
{
    int a = min(x[l],x[r]), b = max(x[l],x[r]);
    int lb = l/SZ, rb = r/SZ;
    int ret = 0;
    if(lb==rb) ret += f(l,r,a-e,b+e);
    else
    {
        ret += f(l,SZ*(lb+1)-1,a-e,b+e);
        for(int i=lb+1; i<rb; ++i) ret += g(i,a-e,b+e);
        ret += f(SZ*rb,r,a-e,b+e);
    }
    return ret;
}

int main()
{
    scanf(" %d", &D);
    rep(i,D) scanf(" %d", &x[i]);

    rep(i,B)
    {
        d[i] = vector<int>(SZ,INF);
        rep(j,SZ)
        {
            int id = i*SZ+j;
            if(id<D) d[i][j] = x[id];
        }

        s[i] = d[i];
        sort(all(s[i]));
    }

    int Q;
    scanf(" %d", &Q);
    while(Q--)
    {
        int l,r,e;
        scanf(" %d %d %d", &l, &r, &e);
        --l; --r;
        printf("%d\n", query(l,r,e));
    }
    return 0;
}

Measured memory_bytes: 4220
public class Main {

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

		int i = 0;
		do {
			int x = sc.nextInt();
			int y = sc.nextInt();
			if (x == 0 && y == 0) {
				break;
			}
			if (x > y) {
				System.out.println(y + " " + x);
			} else if (x < y) {
				System.out.println(x + " " + y);
			}else {
				System.out.println(x + " " + y);
			}

			i++;

		} while (i < 3000);
	}

}



Measured memory_bytes: 36392
s = input()
if len(s) % 2 == 1:
  sl = s[:int((len(s) - 1) / 2)]
  sr = s[int((len(s) +1 ) / 2):]
else:
  sl = s[:int(len(s)/ 2)]
  sr = s[int(len(s) / 2):]

err = 0
for i, c in enumerate(sl):
  err += 1 if c != sr[- i - 1] else 0 

print(err)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define PRINT(a)   cout << (a) << endl
#define RALL(v) rbegin(v), rend(v)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  ll a,v,b,w,t;

  cin >> a >> v >> b >> w >> t;

  cout << (abs(a-b) <= (v-w) * t ? "YES" : "NO") << endl;
}



Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int main(void)
{
    int a,b,c=0;
    cin >> a;
    b=a;
    while(b!=0){
        c+=b%10;
        b/=10;
    }
    if(a%c==0)
        cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#define inf 1<<30
#define maxn 100005
using namespace std;
int main()
{
    int n;
    int a[maxn];
    int b[maxn];
    int k=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
         cin>>a[i];
         if(a[i]==i+1)
         {
             b[k++]=i+1;
         }
    }
   /* cout<<k<<endl;
    for(int i=0;i<k;i++)
        cout<<b[i]<<endl;*/
    if(k==0)
        cout<<"0"<<endl;
    else
    {
        int cnt=0;
        for(int i=0;i<k;i++)
        {
            if(b[i]+1==b[i+1])
            {
                cnt++;
                i++;
            }
            else
                cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A;
        A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
        }
        int count = 0;
        int minj;
        for(int i = 0; i < N; i++){
            minj = i;
            for(int j = i; j < N; j++){
                if(A[j] < A[minj]){
                    minj = j;
                }
            }
            if(minj != i){
                int tmp = A[i];
                A[i] = A[minj];
                A[minj] = tmp;
                count++;
            }
        }
        for(int i = 0; i < N; i++){
            if(i != N-1){
                System.out.print(A[i]+" ");
            }
            else{
                System.out.println(A[i]);
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26340
n = int(input().split()[0])
v_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

score_list = []

for v, c in zip(v_list, c_list):
    if v - c > 0:
        score_list.append(v-c)

ans = sum(score_list)
print(ans)


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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
#define forn(i, n) for(int i = 1; i <= n; i++)
#define rep(i, x, y) for(int i = x; i <= y; i++)
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mii map<int, int>
#define all(x) x.begin(), x.end()
#define N 100001

using namespace std;

const int maxn = 1e9;
const int mod = 1e9 + 7;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;

    a -= b;

    cout << max(c - a, 0);

}

int main() {
	int tt = 1;

	while(tt--) {
		solve();
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << ':' << x << endl;
#define loop3(i, k, n) for(i=k; i<n; i++)
#define ll  long long 
#define loop(i,n) for(int i=0;i<n;i++)
#define loop2(i,n) for(int i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define v1d vector<ll> 
#define v2d vector<vector<ll>>
const int INF = 1e9 +5 ;
int main()
{
    ll n;
    cin>>n;
    v1d v(n);
    double mul = 1;
    loop(i,n)
    {
        cin>>v[i];
        mul *=v[i];
    }

    double sum = 0;
    loop(i,n)
    {
        sum += mul/v[i];
    }
    double ans = mul/sum;
    cout<<ans;
}

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

int main() {
  int N,M;
  cin>>N>>M;
  std::vector<int> a(N+1,0),b(N+1,0);
  int x,y;
  for(int i=0;i<M;i++){
    cin>>x>>y;
    if(x==1)a[y]=y;
    if(y==N)b[x]=x;
  }
  int i=0;
  int j=0;
  int ans=0;
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  while(a[i]==0&&i<N+1)i++;
  while(b[j]==0&&j<N+1)j++;
  if(i<N+1&&j<N+1){
  while(i<N+1&&j<N+1){
    if(a[i]<b[j]){i++;continue;}
    if(a[i]>b[j]){j++;continue;}
    if(a[i]==b[j]){ans=1;break;}
  }}
  if(ans)cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  ll sum = 0;
  vector<int> a(3*N);
  rep(i,3*N) cin >> a[i];
  sort(ALL(a));
  vector<int> s(N),m(3*N),l(3*N);
  rep(i,3*N)
  {
    if(i<N)
    {
      s[i] = a[i];
    }
    else
    {
      if((i-N)%2==0)
      {
        m[i] = a[i];
      }
      else
      {
        l[i] = a[i];
      }
      
    }
  }
  rep(i,3*N)
  {
    sum += m[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 7132
#include<stdio.h>
int main(void)
{
	int card1, card2;
	scanf("%d %d",&card1,&card2);
	if(card1>card2 && card2!=1){
		printf("Alice\n");
	}
	else if(card1>card2 && card2==1){
		printf("Bob\n");
	}
	else if(card1<card2 && card1!=1){
		printf("Bob\n");
	}
	else if(card1<card2 && card1==1){
		printf("Alice\n");
	}
	else if(card1==card2){
		printf("Draw\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int main() {
	int H, W, N, A, C[100][100], count = 0;
	cin >> H >> W >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A;
		for (int j = count; j < count + A; j++) {
			int h = j / W, w = j % W;
			if (h % 2 == 0) C[h][w] = i;
			else C[h][W - w - 1] = i;
		}
		count += A;
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << C[i][j];
			if (j != W - 1) cout << " ";
			else cout << endl;
		}
	}
}

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

#define ll long long
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll x,k,d;
	cin>>x>>k>>d;
	if(x==0)
    {
        if(k%2)
            cout<<d;
        else
            cout<<0;
        return 0;
    }
	ll mn=1e18;
	ll q=abs(x)/d;
	if(k<=q)
    {
        cout<<abs(x)-k*d;
    }
    else
    {
            if(q%2==k%2)
                cout<<abs(x)-q*d;
            else
                cout<<abs(abs(x)-q*d-d);
    }
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(){
  
  int a[5];
  int b;
  
  for(int i = 0; i < 5; i++){
    scanf("%d", &a[i]);
  }
  
  for(int i = 0; i < 5; i++){
    if(a[i] == 0){
      b = i + 1;
      break;
    }
  }
  
  printf("%d\n", b);
  
  return 0;
}

Measured memory_bytes: 1684
import sys
from collections import defaultdict

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    md=998244353
    n,s=MI()
    aa=LI()
    dp=[0]*(s+1)
    dp[0]=1
    inv=pow(2,md-2,md)
    for k,a in enumerate(aa):
        for i in range(s-a,-1,-1):
            dp[i+a]=(dp[i+a]+dp[i]*inv)%md
        #print(k,dp)
    ans=dp[s]*pow(2,n,md)%md
    print(ans)

main()

Measured memory_bytes: 68592
lr=list(map(int,input().split()))
mod=2019
ans=mod**2
if lr[0]%mod<=lr[1]%mod and lr[1]-lr[0]<mod:
    for i in range(lr[0],lr[1]+1):
        for j in range(i+1,lr[1]+1):
            if i*j%mod<ans:
                ans=i*j%mod
else:
    ans=0
print(ans)


Measured memory_bytes: 3060
from bisect import bisect
INF = float('inf')
A,B,Q = map(int,input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

for x in X:
    ans = INF
    i = bisect(S,x)
    for j in {min(i,A-1),max(i-1,0)}:
        s = S[j]
        k = bisect(T,s)
        for l in {min(k,B-1),max(k-1,0)}:
            t = T[l]
            ans = min(ans,abs(x-s)+abs(s-t))
    i = bisect(T,x)
    for j in {min(i,B-1),max(i-1,0)}:
        t = T[j]
        k = bisect(S,t)
        for l in {min(k,A-1),max(k-1,0)}:
            s = S[l]
            ans = min(ans,abs(x-t)+abs(s-t))
    print(ans)

Measured memory_bytes: 105876
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)998244353
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll N=1000005, inf=1e18;
void solve(){
	ll n, m, idx;
	vector<pp> ans;
	cin>>n>>m;
	idx=1;
	for(ll i=m;i>=1;i-=2){
		cout<<idx<<" "<<idx+i<<"\n";
		idx++;
	}
	idx=n;
	for(ll i=m-1;i>=1;i-=2){
		cout<<idx-i<<' '<<idx<<"\n";
		idx--;
	}
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


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

int main()
{
    int N, A;
    cin >> N >> A;
    N = N % 500;
    if (N <= A)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3540
//テンプレ
#include <bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(),(v).end()

using namespace std;
constexpr int MOD = 10e9+7;
constexpr int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  
//




signed main (){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int N,H,W;
    cin >> N >> H >> W;
    cout << (N - H + 1) * (N - W +1) << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int n; cin >> n;
  int a[n];
  FOR(i,0,n-1) cin >> a[i];

  int max = -1001001001;
  int minnow = a[0];

  FOR(i,1,n-1){
    chmax(max,a[i]-minnow);
    chmin(minnow,a[i]);
  }

  cout << max << endl;
}



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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, k=2;
  cin >> n;

  vi h(n);
  rep(i,0,n) cin >> h[i];

  const ll inf = 1e18;
  vl dp(n, inf);
  dp[0] = 0;

  rep(i,0,n-1) {
    rep(j,i+1,min(i+k+1, n)) ckmin(dp[j], dp[i] + abs(h[i]-h[j]));
  }

  cout << dp[n-1] << '\n';

}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	lli n,q,s,t;
	cin >> n >> q >> s >> t;
	vector<lli> h(n+1);
	for(int i=0; i<n+1; i++){
		cin >> h[i];
	}
	vector<lli> hdiff(n);
	for(int i=0; i<n; i++){
		hdiff[i] = h[i+1] -h[i];
	}

	lli ans = 0;
	for(int i=0; i<n; i++){
		if(hdiff[i] > 0) ans -= hdiff[i]*s;
		else ans -= hdiff[i]*t;
	}
	for(int i=0; i<q; i++){
		lli l,r,x;
		cin >> l >> r >> x;
		if(hdiff[l-1] > 0) ans += hdiff[l-1]*s;
		else ans += hdiff[l-1]*t;
		hdiff[l-1] += x;
		if(hdiff[l-1] > 0) ans -= hdiff[l-1]*s;
		else ans -= hdiff[l-1]*t;
		if(r == n){
			cout << ans << endl;
			continue;
		}
		if(hdiff[r] > 0) ans += hdiff[r]*s;
		else ans += hdiff[r]*t;
		hdiff[r] -= x;
		if(hdiff[r] > 0) ans -= hdiff[r]*s;
		else ans -= hdiff[r]*t;
		cout << ans << endl;
	}
    return 0;
}


Measured memory_bytes: 5992
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

int main () {
    int N;
    string  S;
    int AC = 0, WA = 0, TLE = 0, RE = 0;
    
    cin >> N;
    for ( int ii = 0; ii < N; ii++ ) {
        cin >> S;
        if ( S.compare("AC") == 0 ) {
            AC++;
        } else if ( S.compare("WA") == 0 ) {
            WA++;
        } else if ( S.compare("TLE") == 0 ) {
            TLE++;
        } else {
            RE++;
        }
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
    return 0;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF (1LL<<59)

ll d[20][100][100];
vector<int> q[20];
vector<int> r[20];

ll f(ll dist,int c){
	if(dist==INF)return INF;
	ll ret=0;
	for(int i=1;;i++){
		if(q[c][i]<dist){
			ret+=(q[c][i]-q[c][i-1])*r[c][i-1];
		}
		else return ret+(dist-q[c][i-1])*r[c][i-1];
	}
}


int main(){
	int n,m,c,s,g;
	while(cin>>n>>m>>c>>s>>g&&(n||m||c||s||g)){
		rep(i,20)rep(j,100)rep(k,100)d[i][j][k]=INF;
		rep(i,m){
			int x,y,di,cam;
			cin>>x>>y>>di>>cam;
			x--,y--,cam--;
			d[cam][x][y]=min<ll>(di,d[cam][x][y]);
			d[cam][y][x]=min<ll>(di,d[cam][y][x]);
		}
		
		vector<int> b(c);
		rep(i,c)cin>>b[i];
		rep(i,c){
			q[i].resize(b[i]+1);
			q[i][0]=0, q[i][b[i]]=200000000;
			r[i].resize(b[i]);
			rep(j,b[i]-1)cin>>q[i][j+1];
			rep(j,b[i])cin>>r[i][j];
		}
		
		
		rep(p,20){
			rep(wk,n){
				rep(wi,n){
					rep(wj,n){
						d[p][wi][wj] = min(d[p][wi][wk]+d[p][wk][wj],d[p][wi][wj]);
					}
				}
			}
		}
		
		rep(p,20){
			rep(wi,n){
				rep(wj,n){
					d[p][wi][wj] = f(d[p][wi][wj],p);
				}
			}
		}
		
		ll pass[100][100];
		rep(i,100){
			rep(j,100){
				pass[i][j]=INF;
			}
		}
		
		rep(wi,n){
			rep(wj,n){
				rep(p,20){
					pass[wi][wj] = min(pass[wi][wj],d[p][wi][wj]);
				}
			}
		}
		
		rep(wk,n){
			rep(wi,n){
				rep(wj,n){
					pass[wi][wj] = min(pass[wi][wk]+pass[wk][wj],pass[wi][wj]);
				}
			}
		}
		
		if(pass[s-1][g-1]==INF)cout<<-1<<endl;
		else cout<<pass[s-1][g-1]<<endl;
	}
}

Measured memory_bytes: 4712