akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

// -1で初期化
int dp[51][1 << 18] = {};

int dfs(int idx, int mi, int s, int n, vi &o, vi &e) {
  if (dp[mi][s] != -1) {
    return dp[mi][s];
  }
  if (s == 0) {
    dp[mi][s] = 0;
    return 0;
  }
  int ans = 5000000;
  REP(i, n) {
    int _mi = idx % 2 == 0 ? e[i] : o[i];
    if (!((s >> i) & 1) || _mi < mi)
      continue;
    int move = 0;
    REP(j, i) {
      if (((s >> j) & 1)) {
        move++;
      }
    }
    int tmp = dfs(idx + 1, _mi, (s & (~(1 << i))), n, o, e);
    if (tmp != 5000000) {
      ans = min(move + tmp, ans);
    }
  }
  dp[mi][s] = ans;
  return ans;
}

int main() {
  int n;
  cin >> n;
  vi o(n), e(n);
  REP(i, n) {
    if (i % 2 == 0) {
      cin >> e[i];
    } else {
      cin >> o[i];
    }
  }
  REP(i, n) {
    if (i % 2 == 0) {
      cin >> o[i];
    } else {
      cin >> e[i];
    }
  }

  REP(i, 51) {
    REP(j, (1 << 18)) { dp[i][j] = -1; }
  }
  int ans = dfs(0, 0, (1 << n) - 1, n, o, e);
  if (ans == 5000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 52480
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	char op;
	int a, b, answer = 0;
	float DAnswer = 0;

	while (1) {
		cin >> a >> op >> b;

		if (op == '+') {
			answer = a + b;
			cout << answer << endl;
		}
		else if (op == '-') {
			answer = a - b;
			cout << answer << endl;
		}
		else if (op == '*') {
			answer = a * b;
			cout << answer << endl;
		}
		else if (op == '/') {
			DAnswer = (float)a / b;
			answer = floor(DAnswer);
			cout << answer << endl;
		}
		else if (op == '?') {
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 3092
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	_, k, s := nextInt(), nextInt(), nextString()

	runes := []rune(s)
	toLower := func(l rune) rune {
		switch l {
		case 'A':
			return 'a'
		case 'B':
			return 'b'
		case 'C':
			return 'c'
		default:
			return '0'
		}
	}
	runes[k-1] = toLower(runes[k-1])

	s = string(runes)

	fmt.Println(s)
}


Measured memory_bytes: 640
a,b = map(int,input().split())
i = a
j = b
s = 0
t = 0
for s in range(b-1):
    i = i*10
    i += a
for t in range(a-1):
    j = j*10
    j += b
if a < b:
    print(i)
else:
    print(j)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <set>

using namespace std;

string cmp(string s1, string s2, int n) {
    if (s1.length() > s2.length()) {
        return s1;
    } else if (s1.length() < s2.length()) {
        return s2;
    } else {
        if (s1 > s2) {
            return s1;
        } else {
            return s2;
        }
    }

    return "";
}

string forout(string s1, string s2, int n) {
    if (s1[0] == '0')
        return forout(s1.substr(1), s2, n);
    if (s2[0] == '0')
        return forout(s1, s2.substr(1), n);
    return cmp(s1, s2, n);
}

int main() {
    int w, h;
    while (cin >> w >> h, w|h) {
        vector<string> v;
        for (int i = 0; i < h; i++) {
            string s;
            cin >> s;
            v.push_back(s);
        }
        string codes[70][70];
        fill_n((string *)codes, 70*70, "");
        for (int i = w-1; i >= 0; i--) {
            for (int j = h-1; j >= 0; j--) {
                if (v[j][i] >= '0' && v[j][i] <= '9') {
                    codes[j][i] = cmp(v[j][i]+codes[j+1][i], v[j][i]+codes[j][i+1], w);
                }
            }
        }

        string out = "";
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                out = forout(out, codes[j][i], w);
            }
        }
        cout << out << endl;
    }
}

Measured memory_bytes: 1372
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#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(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
const int INF  = 1<<30;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n";

void Main()
{
	string result[3]={"A","B","C"};
	VS S(3);

	REP(i, 3) cin >> S[i];
	ll turn=0;
	while (true){
		if(SIZE(S[turn])==0) break;
		char c=S[turn][0];
		S[turn].erase(S[turn].begin());
		if(c=='a')
			turn=0;
		else if (c=='b')
			turn=1;
		else
			turn =2;
	}

	cout << result[turn] << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
  int A, B, K;
  scanf("%d %d %d", &A, &B, &K);

  for(int i = 0; i < K; i++) {
    // takahashi
    if((i % 2) == 0) {
      if(A % 2) {
	A--;
      }
      B += A / 2;
      A /= 2;
    } else {
      // aoki
      if(B % 2) {
	B--;
      }
      A += B / 2;
      B /= 2;
    }
  }

  printf("%d %d\n", A, B);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  vi h(n);
  rep(i,n) cin >> h[i];
  vi dp(n+5,INF);
  dp[0] = 0;
  rep(i,n) {
    //if (dp[i] == INF) continue;
    chmin(dp[i+1], dp[i] + abs(h[i]-h[i+1]));
    chmin(dp[i+2], dp[i] + abs(h[i]-h[i+2]));
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#define gec getchar
#define puc putchar
#define File(S) (freopen(S".in","r",stdin),freopen(S".out","w",stdout))
using namespace std;
typedef long long ll;
template <typename T>
inline void read(T&a){
	static char ch;
	static bool fg;
	for(ch=gec(),fg=0;ch<'0'||ch>'9';ch=gec())fg^=(ch=='-');
	for(a=0;ch>='0'&&ch<='9';ch=gec())a=((a+(a<<2))<<1)+(ch^'0');
	if(fg)a=-a;
}
template <typename T>
inline void print(T x){
	static int Buf[30],PS=0,BUF;
    if(x<0)puc('-'),x=-x;
    for(;x>=10;x=BUF){
    	BUF=(x/5)>>1;
    	Buf[++PS]=x-((BUF+(BUF<<2))<<1);
    }
    Buf[++PS]=x;
    while(PS)puc('0'^Buf[PS--]);
}
const int N=60;
int n,p,a;
ll f[N][1]; 
int main()
{
	read(n);read(p);
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		read(a);a&=1;
    	f[i][1]=f[i-1][a^1]+f[i-1][1];
    	f[i][0]=f[i-1][a]+f[i-1][0];
	}
	printf("%lld",f[n][p]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[n + 1];
	for (int i = 0; i < n + 1; i++)a[i] = 0;
	int x;
	for (int i = 0; i < n - 1; i++) {
		cin >> x;
		a[x]++;

	}
	for (int i = 1; i <= n; i++)cout << a[i] << "\n";
	return 0;
}

Measured memory_bytes: 4332
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] b = new int[n-1];
		int[] ans = new int[n];
		
		
		for(int i = 0;i < n-1;i++){
			b[i] = saori.saori_hayami();
		}
		ans[0] = b[0];
		for(int i = 1;i < n-1;i++){
			ans[i] = b[i];
			if(ans[i] > b[i-1]){
				ans[i] = b[i-1];
			}
		}
		ans[ans.length-1] = b[b.length-1];
		int num = 0;
		for(int i = 0;i < ans.length;i++){
			num+=ans[i];
		}
		System.out.println(num);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23124
/*
    Tanuj Johal
    
*/
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define ll long long
#define f() for(ll i=0;i<n;i++)
#define begin(v) v.begin,v.end()
#define ump unordered_map<ll,ll>
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);



int main()
{
    fast
    // ll t;cin>>t;while(t--)
    {
        ll n;cin>>n;
        string s;cin>>s;
        ll m = 'Z'-'A';
        m++;
        // cout<<m<<endl;
        for(ll i=0;i<s.size();i++)
        {
            ll k = (int)s[i]-'A';
            k = (k+n)%(m);
            s[i] = 'A'+k;
            cout<<s[i];
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 256
A_B_C_D=input()
m=A_B_C_D.split()
A=m[0]
A=int(A)
B=m[1]
B=int(B)
C=m[2]
C=int(C)
D=m[3]
D=int(D)
while True:
    C-=B
    A-=D
    if  C<=0:
        print('Yes')
        break
    if  A<=0:
        print('No')
        break

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int ans = 0;
  for(int i = 1; i < N + 1; ++i)
  {
    string str = std::to_string(i);
    int keta = str.size();
    if((keta % 2) == 1)
    {
      ++ans;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3724
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import itertools
import math
x = ni()
def is_primes(n):
    primes = [1]*n
    primes[0] =0
    primes[1] =0
    for i in range(2,int(n**0.5)+1):
        if primes[i] ==1:
            for j in range(2*i,n,i):
                primes[j] = 0
    return primes
p = is_primes(10**7)
for i in range(10**7):
    if p[i] and i>=x:
        print(i)
        exit()


Measured memory_bytes: 117360
N, M, P = map(int, input().split())

v = [[] for _ in range(N)]
abc = []
for _ in range(M) :
    a, b, c = map(int, input().split())
    v[b-1].append((a-1, -(c-P)))
    
visited = [False] * N
visited[N-1] = True
queue = [N-1]
while queue :
    cur = queue.pop()
    for nex, cost in v[cur] :
        if not visited[nex] :
            queue.append(nex)
            visited[nex] = True
        abc.append((nex, cur, cost))
        
dist = [float('inf')] * N
dist[0] = 0

def bellmanford() :
    for i in range(N) :
        for a, b, c in abc :
            if dist[a] + c < dist[b] :
                dist[b] = dist[a] + c
                if i == N-1 :
                    return True
    return False
    
if bellmanford() :
    print(-1)
else :
    print(max(0, -dist[N-1]))


Measured memory_bytes: 51820
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 12;
char cn[cm], * ci = cn;
inline int getint() {
	char C = *ci++;
	int A = C - '0';
	while ((C = *ci++) >= '0') A = A * 10 + C - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[3];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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

	fread(cn, 1, cm, stdin);

	int N = getint();
	pair<int, int> X[1001] = {};
	X[0].first = 0;
	rep1(i, N) {
		X[i].first = getint();
		X[i].second = i;
	}

	sort(X + 1, X + N + 1);

	int num[1001] = {};
	rep1(i, N) num[i] = X[i].second - 1;

	int q = 1, q2 = N + 1;
	int OK = 1;
	rep1(i, N) {
		for (int j = X[i - 1].first + 1; j < X[i].first; j++) {
			while (q <= N * 2 && num[q] == 0) q++;
			if (q == N * 2 + 1) {
				OK = 0;
				break;
			}
			if (X[q].first < j) {
				OK = 0;
				break;
			}
			num[q]--;
			putint(X[q].second);
		}
		num[q2] = N - X[i].second;
		X[q2].second = X[i].second;
		X[q2++].first = 300000;
		putint(X[i].second);
	}
	for (int j = X[N].first + 1; j <= N * N; j++) {
		while (q <= N * 2 && num[q] == 0) q++;
		if (q == N * 2 + 1) {
			OK = 0;
			break;
		}
		if (X[q].first < j) {
			OK = 0;
			break;
		}
		num[q]--;
		putint(X[q].second);
	}

	if (OK) {
		printf("Yes\n");
		fwrite(dn, 1, di - dn, stdout);
	}
	else printf("No\n");

	Would you please return 0;
}

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

int main(){
	float xa, ya, xb, yb, xc, yc, xd, yd;
	
	while(scanf("%f,%f,%f,%f,%f,%f,%f,%f", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF){
		float x[4] = {xa,xb,xc,xd};
		float y[4] = {ya,yb,yc,yd};
		float s[4];
		bool allp = true, alln = true;
		
		
		for(int i = 0; i < 4; ++i){
			s[i] = (x[(i+1)%4] - x[i]) * (y[(i+2)%4] - y[(i+1)%4]) - (x[(i+2)%4] - x[(i+1)%4]) * (y[(i+1)%4] - y[i]);
		}
		
		for(int i = 0; i < 4; ++i){
			if(s[i] < 0){
				allp = false;
				break;
			}
		}
		for(int i = 0; i < 4; ++i){
			if(s[i] > 0){
				alln = false;
				break;
			}
		}
		
		if(allp || alln){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
int main(void)
{
  char s[5];
  scanf("%c %c %c",&s[0],&s[1],&s[2]);
  if(s[0]==s[1]&&s[0]==s[2]){
    puts("No");
  }else{
    puts("Yes");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int n, a, b;
	string s;
	cin >> n >> a >> b >> s;
	int alr = 0;
	int alr_b = 0;
	for (auto c : s) {
		int ok = 1;
		ok = ((c == 'a' && alr < a + b) || (c == 'b' && alr < a + b && alr_b < b));
		if (ok) {
			alr++;
			if (c == 'b') alr_b++;
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
	}
}

Measured memory_bytes: 3252
N, M, Q = map(int, input().split())

dp = [[0 for col in range(N)] for row in range(N)]

for i in range(M):
    l, r = map(int, input().split())
    dp[l-1][r-1]+=1

for i in range(N):
    for j in range(N)[:-1]:
        dp[i][j+1] += dp[i][j]
        
for i in range(N)[:0:-1]:
    for j in range(N):
        dp[i-1][j] += dp[i][j]

results = []

for i in range(Q):
    l, r = map(int, input().split())
    results.append(dp[l-1][r-1])

for result in results:
    print(result)


Measured memory_bytes: 10448
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

// utils
func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func abs(a, b int) int {
	return int(math.Abs(float64(a) - float64(b)))
}

//data types

type set map[int]struct{}

type pair struct {
	first  int
	second int
}

func main() {
	sc.Split(bufio.ScanWords)
	h, a := nextInt(), nextInt()

	if h%a == 0 {
		fmt.Print(h / a)
		return
	}
	fmt.Print(h/a + 1)
}


Measured memory_bytes: 640
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("POSSIBLE")
#define p_no() p("IMPOSSIBLE")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

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

    // input
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    sort(ALL(A));
    ll M = A.back();

    ll G = A[0];
    FOR(i, 1, N){
        G = gcd(G, A[i]);
    }

    if(M >= K && K%G==0){
        p_yes();
    }else{
        p_no();
    }
    
    return 0;
}

Measured memory_bytes: 1024
import java.math.BigDecimal
import java.math.MathContext
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextLong()
    val b = sc.nextLong()
    val c = sc.nextLong()
    println(problempanasonic2020c(a, b, c))
}

fun problempanasonic2020c(a: Long, b: Long, c: Long): String {
    fun sqrt(a: BigDecimal, scale: Int): BigDecimal? {
        var x = BigDecimal(Math.sqrt(a.toDouble()), MathContext.DECIMAL64)
        if (scale < 17) {
            x = x.setScale(scale, BigDecimal.ROUND_HALF_EVEN)
            return x
        }
        val b2 = BigDecimal(2)
        var tempScale = 16
        while (tempScale < scale) {
            x = x.subtract(
                x.multiply(x).subtract(a).divide(
                    x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN
                )
            )
            tempScale *= 2
        }
        return x
    }
    return if (sqrt(BigDecimal(a), 18)!!.add(sqrt(BigDecimal(b), 18)) < sqrt(BigDecimal(c), 18)) "Yes" else "No"
}

Measured memory_bytes: 31520
#include <bits/stdc++.h>
#define ll long long
#define pr pair<int,int>
#define F first
#define S second
using namespace std;

int G[510*510],H[510][510];
bool occupy[510][510];
int n,l,r,x;
ll ans;
vector<pr> cd{{0,1},{1,0},{0,-1},{-1,0}};

void dfs(int l,int r){
   int temp=H[l][r]+occupy[l][r];
   for(int i=0;i<4;i++){
      int l1=l+cd[i].F,r1=r+cd[i].S;
      if(H[l1][r1]>temp){
         H[l1][r1]=temp;
         dfs(l1,r1);
      }
   }
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
         occupy[i][j]=true;
         if(min(i-1,n-i)<min(j-1,n-j))
           H[i][j]=min(i-1,n-i);
         else
           H[i][j]=min(j-1,n-j);
      }
    }
    for(int i=1;i<=n*n;i++){
       cin>>x;
       l=ceil((long double)x/(long double)n);
       r=x%n;
       if(!r) r=n;
       ans+=H[l][r];
       occupy[l][r]=false;
       dfs(l,r);

    }
    cout<<ans<<"\n";
}
int main(){
   
   solve();
} 


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

using namespace std;

static const int MAX_X = 1000;

int main() {
    int N, X;

    N = 1;

    cin >> X;

    int max_b = MAX_X;
    int max_n = 1;
    int p = 2;
    int n = 1;

    while (1) {
        max_n = 1;
        for (int b = 2; b <= X; b++) {
            n = int(pow(b, p));
            if (n > X) break;
            max_n = max(max_n, n);
        }
        if (max_n == 1) break;
        N = max(N, max_n);
        p++;
    }

    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 #include <math.h>
using namespace std;
#define ll long long
#define pi 3.14159265359

int main(){
 int n;
  cin>>n;
  if(n%2==0){
    cout<<0.5<<endl;
    return 0;
  }
  int odd=n-n/2;
  double odd2=odd;
  double all=n;
  cout<<odd2/all<<endl;
}
 
    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	auto result = A + B;
	if (result >= 10)
	{
		cout << "error" << endl;
	}
	else
	{
		cout << result << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int N = sc.nextInt();
		String S = sc.next();

		for(int i = 0; i < S.length(); i++) {
			if((int)S.charAt(i) + N < 91) {
				sb.append((char)(S.charAt(i) + N));
			}else {
				sb.append((char)((S.charAt(i) + N) % 90 + 64));
			}
		}

		System.out.println(sb.toString());
		sc.close();
	}
}

Measured memory_bytes: 22868
#include<stdio.h>

#define N 100000
#define Q 1000

int tl=0,head=0,tail=0;
struct data{
  char name[10];
  int time;
};
int main(){
  struct data c[N];
  int a,b,d,i,j[N];
  scanf(" %d %d",&a,&b);
  for(i=0;i<a;i++){
    scanf(" %s %d",c[i].name,&c[i].time);
    tl+=c[i].time;
  }
  d=tl;
  i=0;
  //for(i=0;i<a;i++)printf("%s %d\n",c[i].name,c[i].time);
  while(i<a){
    if((c[i].time-b)<=0){
      tl-=c[i].time;
      c[i].time=0;
      printf("%s %d\n",c[i].name,d-tl);
    }
    else{c[i].time-=b;tl-=b;j[tail]=i;tail++;}
    i++;
  }
  while(tl>0){
    if((c[j[head]].time-b)<=0){
      tl-=c[j[head]].time;
      c[j[head]].time=0;
      printf("%s %d\n",c[j[head]].name,d-tl);
      head=(head+1)%a;
    }
    else{c[j[head]].time-=b;tl-=b;j[tail]=j[head];tail=(tail+1)%a;head=(head+1)%a;}
  }
} 



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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef unsigned long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 2e3 + 5;

int A[N], B[N], CA[N * N], CB[N * N], PSA[N * N], PSB[N * N];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> A[i], CA[A[i]]++;
	for (int i = 1; i <= m; i++) cin >> B[i], CB[B[i]]++;
	for (int i = 1; i <= n * m; i++) if (CA[i] > 1 || CB[i] > 1) die(0);
	for (int i = n * m; i >= 1; i--) PSA[i] = PSA[i + 1] + CA[i], PSB[i] = PSB[i + 1] + CB[i];
	int ans = 1;
	for (int x = n * m; x >= 1; x--) {
		if (CA[x] == 1 && CB[x] == 1) continue;
		if (CA[x] == 1) ans = 1LL * ans * PSB[x] % MOD;
		else if (CB[x] == 1) ans = 1LL * ans * PSA[x] % MOD;
		else ans = 1LL * ans * max(0, PSA[x] * PSB[x] - (n * m - x)) % MOD;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 14592
n,m=map(int,input().split())
p=list(map(int,input().split()))
r=[i for i in range(n)]
def union(x,y):
  rx=root(x)
  ry=root(y)
  if rx==ry:
    return
  else:
    r[rx]=ry
def root(x):
  if x==r[x]:
    return x
  else:
    r[x]=root(r[x])
    return r[x]
for i in range(m):
  a,b=map(int,input().split())
  union(a-1,b-1)
ans=0
for i in range(n):
  if root(i)==root(p[i]-1) or i+1==p[i]:
    ans+=1
print(ans)

Measured memory_bytes: 13880
import sys
from copy import deepcopy

F = sys.stdin
N, K = map(int, F.readline().strip("\n").split())
A = [None] * (N + 1)
A[0] = 0
A_order = {0}
for a in range(N):
    A[a+1] = int(F.readline().strip("\n")) - K + A[a]
    A_order |= {A[a+1]}
maxA = len(A_order)
A_order = list(A_order)
A_order.sort()

compressed_A = dict()
for i in range(maxA):
    compressed_A[A_order[i]] = i

bit = [0] * (maxA + 1)
total_inversion = 0
for i in range(N+1):
    b = compressed_A[A[i]] + 1
    while b <= maxA + 1: 
        bit[b - 1] += 1
        b += b & -b

    #lower sum
    lower = compressed_A[A[i]] + 1
    lower_sum = 0
    while lower > 0:
        lower_sum += bit[lower - 1]
        lower -= lower & -lower

    total_inversion += i + 1 - lower_sum
 
print(N * (N + 1) // 2 - total_inversion)

Measured memory_bytes: 45328
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
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;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,k,c;string s;
  int l[210000], r[210000];
signed main(){
  cin>>n>>k>>c>>s;
  int last = -INF;
  l[0] = 0;
  repd(i,1,n+1){
    if(s[i-1] == 'x' || i-last <= c)l[i] = l[i-1];
    else{
      l[i] = l[i-1]+1;
      last = i;
    }
  }
  last = INF;
  r[n+1] = 0;
  for(int i = n;i >= 1;i--){
    if(s[i-1] == 'x' || last-i <= c)r[i] = r[i+1];
    else{
      r[i] = r[i+1]+1;
      last = i;
    }
  }
  vector<int> ans;
  repd(i,1,n+1){
    if(l[i-1] + r[i+1] < k)ans.push_back(i);
  }
  rep(i,ans.size())cout << ans[i] << endl;
}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i=0; i < n; i++)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
const ll INF = 1LL << 60;
//cout << fixed << setprecision(10);

int main(){
    ll n, m, k, s, ans=0; cin>>n>>m;
    vector<ll> p(m);
    vector<set<ll>> S(m);
    rep(i,m){
        cin>>k;
        rep(j,k){
            cin>>s;
            S[i].insert(s-1);
        }
    }
    rep(i,m) cin>>p[i];
    for(ll bit=0;bit<(1<<n);bit++){
        bool ok=1;
        rep(i,m){
            ll cnt=0;
            for(auto v: S[i]){
                if(bit&(1<<v)){
                    cnt++;
                }
            }
            if(cnt%2!=p[i]){
                ok=0;
                break;
            }
        }
        if(ok) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//priority_queue<int> pque;
//priority_queue<int, vector<int>, greater<int>> pque;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;


int main(void){
    int N;
    cin >> N;
    vector<int> p(N);
    for(int i = 0; i < N; i++){
        cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    int ans = 0;
    for(int i = 0; i < N-1; i++){
        ans += p.at(i);
    }
    ans += p.at(N-1) / 2;
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cmath>
#define PI 3.14159265358979323846264338327950L
using namespace std;
int main(){
  long double a,b,h,m;
  cin>>a>>b>>h>>m;
  long double rad=PI* 2 *
    ((long double)h/ 12.0 + ((long double)m/ 60.0) / 12.0 - (long double)m/ 60.0);
  long double rsq= (long double)(a*a+b*b) - (long double)(2 *a*b) *cosl(rad);
  cout<<fixed<<setprecision(20)<<sqrt(rsq)<<endl;
}

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

const int maxn = 2e2 + 5;
using namespace std;
int ss[maxn];

int main()
{
	int n;
	cin >> n;
	int ok = 0;
	for (int i = 0; i < n; i++) {
		cin >> ss[i];
		if (!ok)
			if (ss[i] % 2)
				ok = 1;
	}
	if (ok) {
		cout << "0" << endl;
		return 0;
	}
	int gcd = ss[0];
	for (int i = 1; i < n; i++)
		gcd = __gcd(gcd, ss[i]);
	int k = 0;
	while (gcd > 1) {
			gcd /= 2;
			k++;
	}	
	cout << k << endl;		
	return 0;
}
 

Measured memory_bytes: 256
// KOI NI YAAR SAB SAHI HOEGA  BAS  CHORRO MAT
// ENJOR KARO YAAR
// HAAR MAT MAANO
// // APNA TIME AAYEGA
// BEILIEVE IN GOD
#include<bits/stdc++.h>
using namespace std;
#define lli int
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define ma 1e18
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double
#define PI  3.14159265358979
#define pri  priority_queue<ll>
#define prim  priority_queue<ll,vector<ll>,greater<ll>>
#define flush  cout<<flush

const lli  N=3e3+10;
 
vector<vector<lld>> dp(N,vector<lld>(N,-1)); 
lli n;
vector<lld>a;



lld solve(lli index , lli tails)
{if(index == n)
{if(tails<=n/2)
{return 1;
}
else
{return 0;
}
}
if(dp[index][tails]!=-1)
{return dp[index][tails];
}
lld res=0;
res = (a[index] * solve(index+1,tails)) + (1-a[index])  *  solve(index+1,tails+1);
return dp[index][tails] = res;
}

int main()
{lli num;
fast();
cin>>n;
a.resize(n);
loop(i,0,n)
{cin>>a[i];
}

cout<<fixed<<setprecision(10)<<solve(0,0)<<"\n";
}


Measured memory_bytes: 145808
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  string s; cin >> s;
  if(n % 2 == 1){
    cout << "No" << endl;
    return 0;
  }
  int m = n / 2;
  for(int i=0; i<m; i++){
    if(s[i] != s[i+m]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3592
import sys

input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]
    N = int(input())
    A = [int(x) for x in input().split()]

    ans = [[0] * W for j in range(H)]

    c = 0
    for j in range(H):
        if j % 2 == 0:
            for i in range(W):
                if A[c] == 0:
                    c += 1
                A[c] -= 1
                ans[j][i] = c + 1
        else:
            for i in range(W - 1, -1, -1):
                if A[c] == 0:
                    c += 1
                A[c] -= 1
                ans[j][i] = c + 1

    for a in ans:
        print(*a)


    
    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 3920
package main

import (
  "fmt"
  "sort"
)

func main() {
  var N,K,a,b int
  fmt.Scan(&N)
  fmt.Scan(&K)
  num := make([]int, N)
  count := make(map[int]int, N)
  for i := 0; i < N; i++ {
    fmt.Scan(&a)
    fmt.Scan(&b)
    num[i] = a
    count[a] += b
  }
  sort.Ints(num)
  order := 1
  previous := 0
  var answer int
  for _, v := range num {
    if previous != v {
      order += count[v]
      if order > K {
        answer = v
        break
      }
      previous = v
    }
  }
  fmt.Println(answer)
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta (bas + (son-bas)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1e18
#define N 1000005
#define lim 10000
using namespace std;
 
typedef long long ll;

int n,ar[N],mx,mx2;

int main()
{

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> ar[i];
		if (ar[i] > mx)
		{
			mx2 = mx;
			mx = ar[i];
		}
		else if(ar[i] > mx2)
			mx2 = ar[i];
	}
	for (int i = 0; i < n; ++i)
	{
		if (ar[i] == mx)
			cout << mx2 << endl;
		else
			cout << mx << endl;
	}
    return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
typedef long long ll;
typedef long double ld;

using namespace std;

int main(){
    cs
    ll h,w;
    cin>>h>>w;
    if(h==1||w==1) cout<<1;
    else cout<<(h*w+1)/2;
}

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

const int MAX_N = int(1e5) + 10;

int n, m, ans_top;
std::vector<int> edges[MAX_N], tree[MAX_N];
std::pair<int, int> el[MAX_N], ans[MAX_N];
int par[MAX_N], deg[MAX_N];
bool in[MAX_N];

void dfs(int x, int p) {
	for (auto y : tree[x]) {
		if (y != p) {
			dfs(y, x);
		}
	}
	if (x == 1) return;
	if (deg[x] & 1) {
		ans[++ans_top] = std::make_pair(x, p);
		++deg[x];
	} else {
		ans[++ans_top] = std::make_pair(p, x);
		++deg[p];
	}
}

int find(int x) {
	return x == par[x] ? x : par[x] = find(par[x]);
}

void solve() {
	for (int i = 1; i <= n; ++i) {
		par[i] = i;
	}
	int tot = 0;
	for (int i = 1; i <= m; ++i) {
		int x = el[i].first, y = el[i].second;
		x = find(x);
		y = find(y);
		if (x != y) {
			in[i] = true;
			tree[el[i].first].push_back(el[i].second);
			tree[el[i].second].push_back(el[i].first);
			par[y] = x;
			++tot;
			if (tot == n - 1) break;
		}
	}
	ans_top = 0;
	for (int i = 1; i <= m; ++i) {
		if (!in[i]) {
			ans[++ans_top] = el[i];
			++deg[el[i].first];
		}
	}
	dfs(1, 0);
}

int main() {
	scanf("%d%d", &n, &m);
	if (m & 1) {
		puts("-1");
		return 0;
	}
	for (int i = 1; i <= m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		edges[x].push_back(y);
		edges[y].push_back(x);
		el[i] = std::make_pair(x, y);
	}

	solve();
	for (int i = 1; i <= m; ++i) {
		printf("%d %d\n", ans[i].first, ans[i].second);
	}
}

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

int ceil(int a, int b){
  return a/b + ((a%b) != 0);
}

int main(){

  long long a[100005], l, r;
  int K;
  cin >> K;
  for(int i=0; i<K; i++) cin >> a[i];
  l = r = 2;

  for(int i=K-1; i>=0; i--){
    
    if(r < a[i]){
      cout << -1 << endl;
      return 0;
    }

    l = 1ll * ((l-1)/a[i] + 1) * a[i];
    r = 1ll * r/a[i] * a[i] + (a[i] - 1);
    if(l > r) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << l << " " << r << endl;
  return 0;
}


Measured memory_bytes: 4376
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
for i in range(n):
    c.append(a[i]-b[i])
c=sorted(c,reverse=1)
if sum(c)<0:
    print(-1)
    exit()
d=0
e=0
f=0
for i in range(n):
    if c[i]<0:
        d+=c[i]
        e+=1
for i in range(n):
    if f>=abs(d):
        break
    f+=c[i]
print(e+i)

Measured memory_bytes: 18708
using System;
using static System.Console;

namespace A
{
  class Program
  {
    static void Main(string[] args)
    {
      string[] inputs = ReadLine().Split();
      int N = int.Parse(inputs[0]);
      int A = int.Parse(inputs[1]);
      int B = int.Parse(inputs[2]);

      int max = Math.Min(A, B);
      int min = A + B - N < 0 ? 0 : A + B - N;
      WriteLine($"{max} {min}");
    }
  }
}


Measured memory_bytes: 13268
def main():
    Nums = map(int, input().split())
    
    SortedNums = sorted(Nums)
    MaxMidDiff = SortedNums[2] - SortedNums[1]
    MaxMinDiff = SortedNums[2] - SortedNums[0]
    
    if((MaxMidDiff - MaxMinDiff)%2 == 0):
        if(MaxMidDiff%2 == 0):
            print(int(MaxMidDiff/2 + MaxMinDiff/2))
        else:
            print(int(MaxMidDiff/2) + int(MaxMinDiff/2) + 1)
    else:
        if(MaxMidDiff%2 == 0):
            MaxMinDiff += 1
        else:
            MaxMidDiff += 1
        print(int(MaxMidDiff/2 + MaxMinDiff/2) + 1 )
        
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(){
  int N,W;
  cin >> N >> W;
  int w[N];
  ll v[N];
  for(int i=0;i<N;i++) cin >> w[i] >> v[i];

  ll dp[W+1];
  fill(dp,dp+W+1,0);
  for(int i=0;i<N;i++){
    for(int j=W;j>0;j--){
      if(dp[j]!=0 && j+w[i]<=W){
        dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
      }
    }
    dp[w[i]]=max(dp[w[i]],v[i]);
  }

  cout << *max_element(dp,dp+W+1) <<endl;
  return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> H(n,0);
    for(int i=0;i<n;i++){
        cin>>H[i];
    }
    vector <int> flag(n,1);
    int s,t;
    for(int i=0;i<m;i++){
       cin>>s>>t;
       s--;
       t--;
       int hs=H[s];
       int ht=H[t];
       if(hs==ht){
           flag[t]=0;flag[s]=0;
       }       
       if(hs>ht){
           flag[t]=0;
       }
       if(hs<ht){
           flag[s]=0;
       }
    }
    int cnt=0;
    for(int i=0;i<n;i++){
        if(flag[i]==1){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 4052
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>
#define PI acos(-1)
typedef long long ll;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 5; 
using namespace std;

int main()
{
	double R;
	scanf("%lf", &R);
	double ans;
	ans = 2 * PI * R;
	printf("%lf\n", ans);
}

Measured memory_bytes: 3784
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

struct UnionFind{
    private:
    vector<int> parent;
    public:
    void reset(int N){
        parent.clear();
        for(int i=0; i<N; i++) parent.push_back(i);
    }
    int root(int a){
        if(parent[a] == a) return a;
        return parent[a] = root(parent[a]);
    }
    void unite(int a, int b){
        int rootA = root(a);
        int rootB = root(b);
        if(rootA != rootB) parent[rootA] = rootB;
    }
    bool same(int a, int b){
        return root(a) == root(b);
    }
};

int main(){
    iostream::sync_with_stdio(false);
    
    int N, M;
    cin >> N >> M;
    int p[100000];
    for(int i=0; i<N; i++){
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf;
    uf.reset(N);
    for(int i=0; i<M; i++){
        int x, y;
        cin >> x >> y;
        uf.unite(x-1, y-1);
    }
    int ans = 0;
    for(int i=0; i<N; i++){
        if(uf.same(i, p[i])) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1276
import java.io.*;
// import java.math.*;
// import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int N, D;
        N = Integer.parseInt (arr[0]);
        D = Integer.parseInt (arr[1]);
        System.out.println ((int)Math.ceil (N / (2.0 * D + 1)));
        return;
    }
}

Measured memory_bytes: 32880
#include<bits/stdc++.h>
#define ll long long
#define db double
#define lowbit(p) (p&(-p))
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define A first
#define B second
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
/*
数轴上一些整点,求有多少种不同移动方案把所有点都推到出口.
方案不同当且仅当存在至少一个点出口位置不同

每个点要么左边出口要么右边出口
那么就是考虑n个数对
(ldis,rdis)
分别表示到左边的出口的距离,到右边出口的距离
如果一个点完全被另外一个点覆盖,确定其他点的方向就能确定它本身,那么这个点可以删掉?
或者说看做在每一个区间里面找一些分割点之类的?

很难判定

把机器人看作是点
(x,y)
那么每次操作可能是
(x-1,y)或者(x,y-1)
然后走到某一条坐标轴之后停下

要同时考虑两维很困难啊...?
如果记dp(x,y)为x坐标已经减去了x,y坐标已经减去了y的方案数.
那么要考虑的点就剩下(P_x,P_y)  P_x\geq x P_y\geq y
考虑能直接转移过来的点

*/
#define mo 1000000007
#define M 200005
struct Reimu{
	int tot,ls[M*60],rs[M*60];
	ll f[M*60];
	void upd(ll l,ll r,ll x,ll y,ll v,int &p){
		if (p==0)p=++tot;
//		printf("p=%d l=%lld r=%lld  v=%lld\n",p,l,r,v);
		if (l==x&&r==y){
//			printf("p=%d l=%lld r=%lld  v=%lld\n",p,l,r,v);
			(f[p]+=v)%=mo;
//			printf("f[%d]=%lld\n",p,f[p]);
			return ;
		}
		ll mid=(l+r)>>1;
		if (y<=mid)upd(l,mid,x,y,v,ls[p]);
		else if (x>mid)upd(mid+1,r,x,y,v,rs[p]);
		else upd(l,mid,x,mid,v,ls[p]),upd(mid+1,r,mid+1,y,v,rs[p]);
	}
	ll qu(ll l,ll r,ll x,int p){
//		printf("%lld %lld %lld  f[%d]=%lld\n",l,r,x,p,f[p]);
		if (!p)return 0;
		if (l==r)return f[p];
		ll mid=(l+r)>>1;
		if (x<=mid)return qu(l,mid,x,ls[p])+f[p];
		else return qu(mid+1,r,x,rs[p])+f[p];	
	}
}T;
const ll inf=1e12;
ll l[M],r[M],L,R,f[M];
int n,m,tot,rt;
pii a[M];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	freopen("1.in","r",stdin);
	int i,x,j;
	ll tmp,res;
	read(n); read(m);
	for (i=1;i<=n;i++){
		read(x);
		a[++tot]=mp(x,i);
	}
	L=0; R=inf;
	for (i=1;i<=m;i++){
		read(x);
		a[++tot]=mp(x,0);
	}
	sort(a+1,a+tot+1);
	tmp=-2*inf;
	for (i=1;i<=tot;i++){
		if (a[i].B){
			l[a[i].B]=a[i].A-tmp;				
		}
		else{
			tmp=a[i].A;
		}
	}
	tmp=2*inf;
	for (i=tot;i>=1;i--){
		if (a[i].B){
			r[a[i].B]=tmp-a[i].A;
		}
		else {
			tmp=a[i].A;
		}
	}
	tot=0;
	for (i=1;i<=n;i++){
		if (l[i]<inf&&r[i]<inf&&l[i]>0&&r[i]>0)a[++tot]=mp(l[i],r[i]);
	}
	sort(a+1,a+tot+1);
	tot=unique(a+1,a+tot+1)-a-1;
	for (i=1;i<=tot;){
//		printf("---- qu-----\n");
		for (j=i;j<=tot&&a[i].A==a[j].A;j++){
			f[j]=T.qu(L,R,a[j].B,rt)+1;
//			printf("%lld %lld\n",a[j].A,a[j].B);
//			printf("f[%d]=%lld\n",j,f[j]);
		}
//		printf("------cal-------\n");
//		printf("rt=%d\n",rt);
//		printf("%lld %lld   %lld %lld\n",L,R,L,a[i].B);
//		printf("---- upd-----\n");
		for (j=i;j<=tot&&a[i].A==a[j].A;j++){
			T.upd(L,R,a[j].B+1,R,f[j],rt);
		}
		i=j;
	}
	res=T.qu(L,R,R,rt)+1;
	res=(res+mo)%mo;
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 36608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int ans = 1;
            for (int i = 0; i < n; i++) {
                if (ans * 2 < ans + k) ans *= 2;
                else ans += k;
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 23508