akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define INF 1LL << 60;
 
int main() {
  
  int N,W;
  cin >> N >> W;

  ll dp[N+100][W+100],w[N+100],v[N+100];
  
  for(int i=1; i <= N ; i++){
    cin >> w[i] >> v[i];
  }
  
  for(int j=0; j <= W; j++){
    dp[0][j] = 0;
  }
  
  for(int i=1; i <= N; i++){
    for(int j=1; j <= W; j++){
      if( w[i] > j){
        dp[i+1][j] = dp[i][j];
      }
      else if(w[i] <= j){
        dp[i+1][j] = max( dp[i][j-w[i]]+v[i], dp[i][j] );
      }
    }
  }
  
  cout << dp[N+1][W] <<endl;
  
}

Measured memory_bytes: 80896
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

typedef pair<int, int> P;
int main(){
    long long n,x;
    cin>>n>>x;
    vector<long long> v(n);
    rep(i,n){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    vector<long long> w(n-1);
    if(n==1){
        cout<<abs(v[0]-x)<<endl;
        return 0;
    }
    rep(i,n-1){
        w[i]=v[i+1]-v[i];
    }
    long long ans=__gcd(w[0],w[1]);
    for(int i=2; i<n-1; i++){
        ans=__gcd(w[i],ans);
    }
    long long mx=0;
    rep(i,n){
       mx=max(__gcd(ans,abs(x-v[i])),mx);
    }
        
    cout<<mx<<endl;
    return 0;
}



Measured memory_bytes: 1792
;; E - Yutori

(defun n-holidays (n c s)
  "今日から各日までに取得可能な休日数の配列を返す."
  (loop with n-hol = (make-array n)
        for i below n
        for p = (- i c 1)
        do (setf (aref n-hol i)
                 (max (if (> i 0) (aref n-hol (1- i)) 0) ; 休まない
                      (+ (if (>= p 0) (aref n-hol p) 0) ; c+1日前
                         (if (eql (aref s i) #\o) 1 0))))
        finally (return n-hol)))

(defun yutori (n k c s)
  "必ず働く日のリスト"
  (let ((n-hol (n-holidays n c s)) ; その日までに取得可能な休日数
        (n-hol-r (nreverse (n-holidays n c (reverse s))))) ; 以降の休日数
    (loop for i below n
          when (and (eql (aref s i) #\o)
                    (< (+ (if (> i 0) (aref n-hol (1- i)) 0)
                          (if (< i (1- n)) (aref n-hol-r (1+ i)) 0))
                       k))
          collect (1+ i))))

(defun main ()
  (let ((n (read))
        (k (read))
        (c (read))
        (s (read-line)))
    (format t "~{~a~%~}" (yutori n k c s))))

(main)


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

using namespace std;

const int MAXN = 1e5 + 10;

int n;
vector<int> adj[MAXN];

int dfs(int v, int p = -1){
	int cnt = 0;
	for (int u:adj[v])
		if (u^p){
			int x = dfs(u, v);
			if (x)
				cnt++;
		}

	if (!cnt){
		if (~p)
			return 1;
		cout << "First\n";
		exit(0);
	}
	if (cnt == 1) return 0;
	cout << "First\n";
	exit(0);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++){
		int a, b;	cin >> a >> b, a--, b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(0);
	cout << "Second\n";
	return 0;
}


Measured memory_bytes: 5888
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

int main()
{
    long long n, ans;
    std::cin >> n;
    std::vector<long long> as(n), bs(n);
    for (size_t i = 0; i < n; i++) {
        std::cin >> as[i] >> bs[i];
    }
    std::sort(as.begin(), as.end());
    std::sort(bs.begin(), bs.end());
    if (n % 2 == 0) {
        ans = (bs[n / 2] - as[n / 2] + bs[n / 2 - 1] - as[n / 2 - 1])+1;
    } else {
        ans = (bs[(n - 1) / 2] - as[(n - 1) / 2])+1;
    }

    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6056
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>

using namespace std;
int main()
{
	int A, B;
	cin >> A >> B;

	int Ans = (A - 1)*(B - 1);

	cout << Ans;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define CP_X 0
#define CP_Y 1
#define CP_D 2

int N,K;
struct {
	int x1,y1,d1;
	int x2,y2,d2;
} fishes[50];

int cp_num[3]={0,0,0};
int cp[3][110];

void add_cp(int id,int num) {
	int i,pos;
	for(i=0;i<cp_num[id];i++) {
		if(cp[id][i]==num)return;
		if(cp[id][i]>num)break;
	}
	pos=i;
	for(i=cp_num[id];i>pos;i--)cp[id][i]=cp[id][i-1];
	cp[id][pos]=num;
	cp_num[id]++;
}

int get_cp(int id,int num) {
	int left,right,mid;
	left=0;right=cp_num[id]-1;
	while(left<=right) {
		mid=(left+right)/2;
		if(cp[id][mid]==num)return mid;
		else if(cp[id][mid]<num)left=mid+1;
		else right=mid-1;
	}
	return cp_num[id];
}

int imos[110][110][110];

int main(void) {
	int i,j,k;
	long long result;
	scanf("%d%d",&N,&K);
	for(i=0;i<N;i++) {
		scanf("%d%d%d%d%d%d",
			&fishes[i].x1,&fishes[i].y1,&fishes[i].d1,
			&fishes[i].x2,&fishes[i].y2,&fishes[i].d2);
		add_cp(CP_X,fishes[i].x1);
		add_cp(CP_X,fishes[i].x2);
		add_cp(CP_Y,fishes[i].y1);
		add_cp(CP_Y,fishes[i].y2);
		add_cp(CP_D,fishes[i].d1);
		add_cp(CP_D,fishes[i].d2);
	}
	for(i=0;i<N;i++) {
		int x1,y1,d1,x2,y2,d2;
		x1=get_cp(CP_X,fishes[i].x1);
		x2=get_cp(CP_X,fishes[i].x2);
		y1=get_cp(CP_Y,fishes[i].y1);
		y2=get_cp(CP_Y,fishes[i].y2);
		d1=get_cp(CP_D,fishes[i].d1);
		d2=get_cp(CP_D,fishes[i].d2);
		imos[x1][y1][d1]++;
		imos[x1][y2][d1]--;
		imos[x2][y1][d1]--;
		imos[x2][y2][d1]++;
		imos[x1][y1][d2]--;
		imos[x1][y2][d2]++;
		imos[x2][y1][d2]++;
		imos[x2][y2][d2]--;
	}
	for(k=0;k<cp_num[CP_D];k++) {
		for(j=0;j<cp_num[CP_Y];j++) {
			for(i=1;i<cp_num[CP_X];i++) {
				imos[i][j][k]+=imos[i-1][j][k];
			}
		}
		for(j=1;j<cp_num[CP_Y];j++) {
			for(i=0;i<cp_num[CP_X];i++) {
				imos[i][j][k]+=imos[i][j-1][k];
			}
		}
	}
	for(k=1;k<cp_num[CP_D];k++) {
		for(i=0;i<cp_num[CP_X];i++) {
			for(j=0;j<cp_num[CP_Y];j++) {
				imos[i][j][k]+=imos[i][j][k-1];
			}
		}
	}
	result=0;
	for(i=0;i<cp_num[CP_X];i++) {
		for(j=0;j<cp_num[CP_Y];j++) {
			for(k=0;k<cp_num[CP_D];k++) {
				if(imos[i][j][k]>=K) {
					result+=
						(long long)(cp[CP_X][i+1]-cp[CP_X][i])*
						(long long)(cp[CP_Y][j+1]-cp[CP_Y][j])*
						(long long)(cp[CP_D][k+1]-cp[CP_D][k]);
				}
			}
		}
	}
	printf("%lld\n",result);
	return 0;
}

Measured memory_bytes: 5308
a,b=input().split(" ")
a=int(a)
b=int(b)
for i in range(a+1): #10000
  for j in range(a+1-i): #5000
    if i*10000+j*5000+(a-j-i)*1000==b:
      print("{} {} {}".format(i,j,(a-j-i)))
      exit()
print("-1 -1 -1")
    

Measured memory_bytes: 2940
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

const int A[10] = { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 };

int main() {
    int M;
    cin >> M;
    vector<int> d(M);
    vector<ll> c(M);
    rep(i, M) cin >> d[i] >> c[i];

    ll ans = -1;
    int cur = 0;
    rep(i, M) {
        int dnow = d[i];
        ll cnt = c[i];
        while (cnt > 1) {
            if (cnt % 2) {
                cur += dnow;
                ans++;
                if (cur > 9) {
                    cur = cur / 10 + cur % 10;
                    ans++;
                }
            }

            ans += cnt / 2;
            if (dnow >= 5) ans += cnt / 2;
            dnow = A[dnow];
            cnt /= 2;
        }

        if (cnt) {
            cur += dnow;
            ans++;
            if (cur > 9) {
                cur = cur / 10 + cur % 10;
                ans++;
            }
        }
    }

    write(ans);
}

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

int main()
{
  string N;
  cin >> N;
  vector<char> op = {'+', '-'};

  rep(op1, 2) rep(op2, 2) rep(op3, 2)
  {
    int N1 = N[0] - '0';
    int N2 = N[1] - '0';
    int N3 = N[2] - '0';
    int N4 = N[3] - '0';

    if (op[op1] == '-')
      N2 *= -1;
    if (op[op2] == '-')
      N3 *= -1;
    if (op[op3] == '-')
      N4 *= -1;
    int num = N1 + N2 + N3 + N4;
    if (num == 7)
    {
      N2 = abs(N2);
      N3 = abs(N3);
      N4 = abs(N4);
      cout << N1 << op[op1] << N2 << op[op2] << N3 << op[op3] << N4 << "=7" << endl;
      return 0;
    }
  }
}

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

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a % b);
}
/*新たな文字列の偶数文字目をSの各文字に変える
*/


int main() {
  ll A,B;
  cin >> A >> B;
  ll g = gcd(A,B);
  ll lcm = A*B/g;
  cout << lcm << endl;

 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pp push_back
#define fr first
#define sc second

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0) ,cout.tie(0);
    int n ,m; cin  >> n >> m;
    for(int i = 0;i <m;i++){
        int x; cin >> x;
        n -= x;
    }
    cout << max(-1 , n) << '\n';

    return 0;
}


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

using namespace std;

int main() {
	string s;
	cin >> s;

	if(s == "SUN") printf("7\n");
	if(s == "MON") printf("6\n");
	if(s == "TUE") printf("5\n");
	if(s == "WED") printf("4\n");
	if(s == "THU") printf("3\n");
	if(s == "FRI") printf("2\n");
	if(s == "SAT") printf("1\n");
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int main(){
  int N, K;
  int A;
  int i;
  scanf("%d %d", &N, &K);
  for(i=0;i<N;i++){
    scanf("%d", &A);
  }
  
  int n;
  n = ceil((double)(N-1)/(K-1));
  
  printf("%d", n);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int32_t main(){
    fast_io;
    int n;
    cin >> n;
    int a[n];
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
    	cin >> a[i];
    	if(i and a[i - 1] > a[i]) {
    		ans += a[i - 1] - a[i];
    		a[i] = a[i - 1];
    	}
    }
    show(ans);
    return 0;
}

Measured memory_bytes: 5148
def main():
    l = int(input())
    nums = [int(input()) for _ in range(l)]
    dp = [[0 for _ in range(5)] for _ in range(l + 1)]

    for i in range(l):
        dp[i + 1][0] = dp[i][0] + nums[i]
        dp[i + 1][1] = min(dp[i][:2]) + (nums[i] % 2 if nums[i] != 0 else 2)
        dp[i + 1][2] = min(dp[i][:3]) + (nums[i] + 1) % 2
        dp[i + 1][3] = min(dp[i][:4]) + (nums[i] % 2 if nums[i] != 0 else 2)
        dp[i + 1][4] = min(dp[i]) + nums[i]

    print(min(dp[l]))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 74064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		String[] ko = s.split(",", 0);
		String syuturyoku = ko[0] + " " + ko[1] + " " + ko[2];
		System.out.println(syuturyoku);
	}
}


Measured memory_bytes: 8148
function Main(input) {
  input = input.split("\n");
  N = parseInt(input[0]);
  A = input[1].split("");
  B = input[2].split("");
  C = input[3].split("");
  var ans=0;
  for(var i=0;i<N;i++){
    if(A[i]==B[i]&&A[i]==C[i]){

    }else if((A[i]==B[i]&&A[i]!=C[i])||(A[i]==C[i]&&A[i]!=B[i])||(A[i]!=B[i]&&B[i]==C[i])){
      ans++;
    }else{
      ans+=2;
    }
  }



  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>

int main(void){
    int a, b;
    std::string A, B, ans="EQUAL";
    std::cin >> A >> B;
    a = A.size();
    b = B.size();

    if (a > b) {
        ans = "GREATER";
    } else if (a < b){
        ans = "LESS";
    } else {
        for (int i=0; i<a; ++i){
            if (A.at(i) > B.at(i)){
                ans = "GREATER";
                break;
            } else if (A.at(i) < B.at(i)){
                ans = "LESS";
                break;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3600
object Main extends App {
        
        def points2Color(n: Int): Int = {
            n match {
                case n if n < 400 => 1
                case n if n < 800 => 2
                case n if n < 1200 => 3
                case n if n < 1600 => 4
                case n if n < 2000 => 5
                case n if n < 2400 => 6
                case n if n < 2800 => 7
                case n if n < 3200 => 8
                case _ => 0
            }
        }
        
        val sc = new java.util.Scanner(System.in)
        val N = sc.nextInt
    	val as = Array.fill(N)(sc.nextInt).map(points2Color(_))
        
        val tcn = as.filter(_ == 0).length
        val cn  = as.filter(_ != 0).groupBy(identity).size
        
        val min_color = if (tcn > 0 && cn == 0) 1 else cn
        val max_color = tcn+cn
        
        println(s"${min_color} ${max_color}")
    }

Measured memory_bytes: 25680
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int 
#define pb   push_back
#define mp   make_pair
#define F    first
#define S    second
int main()
{
    ll n,i;
    cin>>n;
    ll a[n],b[100001],c[100001];
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    for(i=0;i<n;i++){
            cin>>a[i];
            if(i%2==0){
                b[a[i]]++;
            }
            else{
                c[a[i]]++;
            }
    }
    ll mx1=0,mx2=0,ans,mx3=0,mx4=0,ans1,ans2,x,y;
    vector<pair<ll,ll> > vi1,vi2;
    for(i=0;i<100001;i++){
            if(b[i]>0){
                vi1.pb(mp(b[i],i));
            }
    }
    for(i=0;i<100001;i++){
        if(c[i]>0){
            vi2.pb(mp(c[i],i));
        }
    }
    sort(vi1.begin(),vi1.end());
    sort(vi2.begin(),vi2.end());
    if(vi1.size()==1&&vi2.size()==1){
    	if(vi1[0].second==vi2[0].second){
    		ans=n-vi1[0].first;
		}
		else{
			ans=0;
		}
	}
	else{
		for(i=0;i<vi1.size();i++){
			if(mx1<vi1[i].first){
				mx1=vi1[i].first;
				x=vi1[i].second;
			}
		}
		for(i=0;i<vi2.size();i++){
			if(x!=vi2[i].second){
				mx2=max(mx2,vi2[i].first);
			}
		}
		ans1=n-mx1-mx2;
		for(i=0;i<vi2.size();i++){
			if(mx3<vi2[i].first){
				mx3=vi2[i].first;
				y=vi2[i].second;
			}
		}
		for(i=0;i<vi1.size();i++){
			if(y!=vi1[i].second){
				mx4=max(mx4,vi1[i].first);
			}
		}
		ans2=n-mx3-mx4;
		ans=min(ans1,ans2);
	}
    if(n==2){
        if(a[0]==a[1]){
            cout<<1;
        }
        else{
            cout<<0;
        }
    }
    else{
        cout<<ans;
    }
}

Measured memory_bytes: 4852
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5;
const int INF = 0x7f7f7f7f;
typedef long long ll;
int a[maxn];
int main()
{
    int n;
    cin>>n;
    ll sum=0,tem=0;
    ll minn=INF;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=0;i<n-1;i++)
    {
        tem+=a[i];
        ll rem=sum-tem;
        if(abs(rem-tem)<minn)
        {
            minn=abs(rem-tem);
        }
    }
    cout << minn << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int a;
long double b;

signed main() {
	cin >> a >> b;
	int ans = a * b;
	cout << ans << endl;
}

Measured memory_bytes: 3744
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
map<string,int> tmp;
//int cc=0;
//#define edg(a,b) ((abs((a)-(b))==1))
int ask(string s)
{
	int r=0;
	for(int i=0;i<s.size();i++) r+=(s[i]=='1');
	if(r<=1) return 0;
	if(tmp.count(s)) return tmp[s];
	/*
	++cc; vi rp;
	for(int i=0;i<s.size();i++)
		if(s[i]=='1') rp.pb(i);
	if(rp.size()==2)
	return tmp[s]=edg(rp[0],rp[1]);
	if(rp.size()!=3) throw "RE";
	bool a=edg(rp[0],rp[1]),b=edg(rp[0],rp[2]),
	c=edg(rp[1],rp[2]);
	return tmp[s]=a+b+c;*/
	cout<<"? "<<s<<endl;
	int x; cin>>x; return tmp[s]=x;
}
int n,ff[SZ]; vector<int> vs[SZ],rs;
int gf(int x) {return ff[x]?ff[x]=gf(ff[x]):x;}
void uni(int a,int b)
{int ga=gf(a),gb=gf(b);if(ga^gb)ff[ga]=gb;}
int cnt()
{
	int ans=0; rs.clear();
	for(int i=1;i<=n;i++) vs[i].clear();
	for(int i=1;i<=n;i++)
	{
		vs[gf(i)].pb(i);
		if(gf(i)==i);else continue;
		++ans; rs.pb(i);
	}
	random_shuffle(rs.begin(),rs.end());
	for(int i=1;i<=n;i++)
		random_shuffle(vs[i].begin(),vs[i].end());
	return ans;
}
const int B=12;
vector<pii> es;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) vs[i].pb(i);
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<i;j+=B)
		{
			string s; s.resize(n);
			for(int i=0;i<n;i++) s[i]='0';
			for(int k=0;k<B&&j+k<i;++k) s[j+k-1]='1';
			int a=ask(s); s[i-1]='1';
			int b=ask(s);
			if(a==b) continue;
			for(int k=0;k<B&&j+k<i;++k)
			{
				for(int i=0;i<n;i++) s[i]='0';
				s[j+k-1]=s[i-1]='1';
				if(ask(s)==1)
					es.pb(pii(j+k,i));
			}
		}
	}
	cout<<"!";
	for(auto r:es) printf(" (%d,%d)",r.fi-1,r.se-1);
	puts("");
	//cerr<<cc<<"\n";
}


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

int main() {
	int n;
	cin >> n;
	bool ans = true;
	vector<pair<int ,int>> se(n);
	vector<int> da(n),dv(n),rist(n);
	for (int i = 0;i < n;i++) {
		cin >> da[i];
		dv[i] = i + 1 - da[i];
	}
	for (int i = 0;i < n;i++) {
		int x;
		bool fu = false;
		for (int j = n-1;j > -1;j--) {
			if (dv[j] == 0) {
				fu=true;
				x = j;
				break;
			}
		}
		if (!fu) {
			ans = false;
			break;
		}
		for (int j = n - 1;j > x;j--) {
			dv[j]--;
		}
		dv[x] = -1;
		rist[n - 1 - i] = da[x];
	}
	if (ans) {
		for (int i = 0;i < n;i++) {
			cout << rist[i] << endl;
		}
	}
	else
		cout << "-1" << endl;
}

Measured memory_bytes: 256
n = int(input())
str_list = []

for i in range(n):
    s = input()
    str_list.append(s)

import collections

c = collections.Counter(str_list)

x = c.most_common()
str_list_2 = []

num = x[0][1]
for i in x:
    if i[1] != num:
        break
    else:
        str_list_2.append(i[0])

str_list_2.sort()

for i in str_list_2:
    print(i)


Measured memory_bytes: 47696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    ll n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i < n;i++)
    {
        cin>>v.at(i);
    }

    sort(v.begin(),v.end());

    cout<<(v.at(n/2)-v.at(n/2 -1) )<<endl;
}

Measured memory_bytes: 768
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: u64
    }
    let mut k = n / 11 * 2;
    if n % 11 <= 6 && n % 11 >= 1 {
        k += 1;
    }
    if n % 11 > 6 {
        k += 2;
    }
    println!("{}", k);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int x[n]={0};
    int i;
    int co=0;
    for(i=0;i<n;i++){
        cin >> x[i];
        if((x[i])<=abs(x[i]-k)){
            co+=x[i];
        }
        else{
            co+=abs(x[i]-k);
        }
    }
    cout << 2*co << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

int w,h,sy,sc,gy,gc,ans;
char t[55][55];
int s[55][55];
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

void bfs(int h,int w,int sy,int sx,int gy,int gx,int dt){
    if(sy<=0||sx<=0)return;
    if(sy>h||sx>w)return;
    if(t[sy][sx]=='#')return;
    if(s[sy][sx]<=dt)return;
    s[sy][sx]=dt;
    if(sy==gy && sx==gx){
        ans=dt;
        return;
    }
    dt++;
    rep(i,0,4){
        int ny=sy+dy[i];
        int nx=sx+dx[i];
        bfs(h,w,ny,nx,gy,gx,dt);
    }
    return;
}

int main(){
    int w,h,sy,sx,gy,gx,cnt=0;
    cin>>h>>w;
    sy=1;
    sx=1;
    gy=h;
    gx=w;
    repe(i,1,55){
        repe(j,1,55)s[i][j]=11111;
    }
    repe(i,1,h){
        repe(j,1,w){
            cin>>t[i][j];
            if(t[i][j]=='#')cnt++;
        }
    }
    bfs(h,w,sy,sx,gy,gx,0);
    if(ans==0)cout<<"-1"<<endl;
    else cout<<h*w-ans-1-cnt<<endl;
    return 0;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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; }
 



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

    ll X;
    cin >> X;


    ll base=X;

    ll cnt=1;
    ll bbase=100;
    while(bbase<base)
    {
        bbase*=1.01;
        cnt++;
    }

    cout << cnt-1 << endl;

 

 

    return 0;
}



Measured memory_bytes: 3664
/*
1.树拓扑可以开贪心，子节点合并到父节点
2.若合并前面对后面有影响，可以使用比例排序 
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#define MAXN 200010
using namespace std;
#define int long long
struct Node{int idx,ct1,ct2;};
struct CMP{inline bool operator()(const Node&a,const Node&b){return a.ct1*b.ct2 < a.ct2*b.ct1;}};
int cnt1[MAXN], cnt2[MAXN];
/*
a < b:
count1 a/count2 b < count1 b / count2 b
*/
typedef priority_queue<Node,vector<Node>,CMP> PQC;
PQC q;
int n,fa[MAXN],f[MAXN],u,ans;
int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
signed main(){
	ios_base::sync_with_stdio(false);
	cin>>n;
	for(int i=2;i<=n;++i)cin>>fa[i];
	for(int i=1,t;i<=n;++i){
		cin>>t;
		cnt1[i]=!(cnt2[i]=t);
		f[i]=i;
	}
	for(int i=2;i<=n;++i)
		q.push((Node){i,cnt1[i],cnt2[i]});
	Node t;
	while(!q.empty()){
		u=(t=q.top()).idx;q.pop();
		if(t.ct1==cnt1[u]&&t.ct2==cnt2[u]){//去掉重复的父节点(下面无法像set一样清除父节点) 
			int y=f[u]=find(fa[u]);
			ans+=cnt2[y]*cnt1[u];
			cnt1[y]+=cnt1[u];
			cnt2[y]+=cnt2[u];
			if(y!=1)q.push((Node){y,cnt1[y],cnt2[y]});
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14832
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

int main() {

	int A, B;

	scanf("%d%d", &A, &B);


	printf("%d\n", A*B - A - B + 1);

	return 0;
}

Measured memory_bytes: 256
Imports System

Module Program
    Sub Main(args As String())

        Dim HWK() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()

        Dim c As New List(Of Integer)

        Dim kuroBak As New List(Of Integer)


        For i As Integer = 0 To HWK(0) - 1
            Dim tmp As String = Console.ReadLine()
            For j As Integer = 0 To HWK(1) - 1
                If Mid(tmp, j + 1, 1) = "#" Then
                    kuroBak.Add(i * 6 + j + 1)
                End If
            Next
        Next

        Dim r As Integer = 0

        For i As Integer = 0 To 2 ^ HWK(0) - 1
            Dim kuro As List(Of Integer) = New List(Of Integer)(kuroBak)
            Call Gyo(kuro, i)
            For j As Integer = 0 To 2 ^ HWK(1) - 1
                Dim kuro2 As List(Of Integer) = New List(Of Integer)(kuro)
                Call Retu(kuro2, j)
                If kuro2.Count() = HWK(2) Then
                    r += 1
                End If
            Next
        Next

        Console.WriteLine(r)

    End Sub

    Private Sub Gyo(hp As List(Of Integer), i As Integer)

        For g As Integer = 6 To 0 Step -1
            If i >= 2 ^ g Then
                i -= 2 ^ g
                For os = 0 To 5
                    hp.Remove((g + 1) * 6 - os)
                Next
            End If
        Next

    End Sub
    Private Sub Retu(wp As List(Of Integer), j As Integer)

        For r As Integer = 6 To 0 Step -1
            If j >= 2 ^ r Then
                j -= 2 ^ r
                For os = 0 To 5
                    wp.Remove((r + 1) + os * 6)
                Next
            End If
        Next

    End Sub

End Module


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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define print(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int bexp(int a, int b, int mod)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

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

const int N = 100010;
const int mod = 998244353;

struct comp {
    bool operator() (const pair<int, int> a, const pair<int, int> b) const
    {
        return a.ss > b.ss;
    }
};

int32_t main() 
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int n, k;
    cin >> n >> k;

    int l, r;
    pair<int, int> p[k];
    for (int i = 0; i < k; ++i)
    {
        cin >> p[i].ff >> p[i].ss;
    }

    sort(p, p + k);
    int dp[n] = {};
    int cum[n];
    memset(cum, -1, sizeof(cum));

    dp[0] = 1;
    cum[0] = 1;
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < k; ++j) {
            
            if (i - p[j].ff < 0) {
                break;
            }

            dp[i] = (dp[i] + mod + cum[i - p[j].ff] - (i - p[j].ss <= 0 ? 0 :cum[ i - p[j].ss - 1])) % mod;
        }
        cum[i] = (cum[i - 1] + dp[i]) % mod;
        // cout << dp[i] << " : " << cum[i] << "\n";
    }


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

Measured memory_bytes: 6704
n, m = map(int, input().split())

xy = [i for i in range(n + 1)]


def root(x):
    i = x
    while i != xy[i]:
        i = xy[i]
    xy[x] = i
    return i


for _ in range(m):
    x, y, z = map(int, input().split())
    rx = root(x)
    ry = root(y)
    if rx != ry:
        xy[ry] = rx

ans = -1
for i, v in enumerate(xy):
    if i == v:
        ans += 1

print(ans)


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

int main() {
	int S, W;
	cin >> S >> W;
	
	if (S <= W) {
		cout << "unsafe";
	}
	else {
		cout << "safe";
	}

	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;

# define pi           3.14159265358979323846 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double t = 60 * h + m;// time minutes
  double ra = 0.5 * t;
  double rb = 6.0 * t;
  double del = abs(ra - rb);
  if( del > 180.0 ) {
    del = 360.0 - del;
  }
  if( del < 0 ) {
    del = del * -1.0 ;
  }
  double ret = (1.0 * a * a) + (1.0 * b * b) - (2.0 * a * b * cos(del * pi / 180.0));
  ret = sqrt(ret);
  printf("%.15lf\n",ret);
  return 0;
}



Measured memory_bytes: 3676
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<vector<int>>edge(N + 1);
	for (int i = 1; i < N; i++) {
		cin >> L >> R;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<int>dis(N + 1, MOD);
	vector<int>parent(N + 1);
	dis[1] = 0;
	queue<int>Q;
	Q.push(1);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (dis[i] > dis[cn] + 1) {
				dis[i] = dis[cn] + 1;
				Q.push(i);
				parent[i] = cn;
			}
		}
	}
	vector<int>used(N + 1);
	vector<int>nim(N + 1);
	for (int i = 2; i <= N; i++) {
		if (edge[i].size() == 1)Q.push(i);
	}
	edge[1].clear();
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		if (cn == 1)continue;
		int node = cn;
		int nx;
		while (1) {
			nx = parent[node];
			used[node]++;
			used[nx]++;
			node = nx;
			if (edge[nx].size() != 2) {
				break;
			}
		}
		nim[node] ^= (dis[cn] - dis[node]+nim[cn]);
		//nim[node] ^= nim[cn];
		if (edge[node].size() - used[node] == 1)Q.push(node);
	}
	if (!nim[1])cout << "Bob\n";
	else cout << "Alice\n";
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
const int N=1e4+10;
void solve()
{
    ll h,n;
    cin>>h>>n;
    vector<PLL> arr(n);
    fr(i,0,n)
    {
        cin>>arr[i].F>>arr[i].S;
    }
    VL ans(N,inf);
    ans[0]=0;
    fr(i,1,1e4+2)
    {
        fr(j,0,n)
        {
            //if((i-arr[j].F)<=0)
            {
                if((i-arr[j].F)<=0)
                    ans[i]=min(ans[i],arr[j].S);
                else
                    ans[i]=min(ans[i],ans[i-arr[j].F]+arr[j].S);
            }
        }
    }
    ll f=inf;
    fr(i,1,N)
    {
        if(i>=h)
        {
            f=min(f,ans[i]);
        }
    }
    cout<<f<<endl;
    //cout<<"yo\n"<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
 
int main() {
  int N, K; cin >> N >> K;
  int result = 1;
  for (int i; i<N; i++) {
    if ( result < K ) result *= 2;
    else result += K;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
     
    using namespace std;
     
    int main() {
        int a, b;
        cin >> a >> b;
        
        int cnt = 0;
        int plug = 1;
        while (plug < b) {
            plug += a - 1;
            cnt++;
        }
     
        cout << cnt << endl;
    }

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
const ll inf = 1e18;


const int K = (1<<9);

int n;
ll v[maxn], w[maxn];
vector<pair<ll,ll>> dp[K+10];



vector<pair<ll,ll>> all;


void go(int at, ll val, ll wei) {
    if (at==0) {
	all.push_back({wei, val});
	return;
    }
    go(at/2, val, wei);
    go(at/2, val+v[at], wei+w[at]);
}

void compute(int at) {
    all.clear();
    go(at, 0, 0);
    sort(all.begin(), all.end());

    auto &res = dp[at];
    for (auto p: all) {
	if (res.empty() || res.back().second < p.second) {
	    res.push_back(p);
	}
    }
}


ll dfs(int at, ll val, ll sack) {
    if (sack<0) {
	return -inf;
    }
    if (at==0) {
	return val;
    }
    if (at<=K) {
	auto iter = std::prev(upper_bound(dp[at].begin(),
					  dp[at].end(),
					  make_pair(sack, inf)));
	return val+iter->second;
    }
    return max(dfs(at/2, val, sack), dfs(at/2, val+v[at], sack-w[at]));
}


ll solve(int at, ll L) {
    return dfs(at, 0, L);
}


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

    cin>>n;
    for (int i=1; i<=n; i++) {
	cin>>v[i]>>w[i];
    }


    // O(512 * 512) = O(10^5) precompute
    for (int i=1; i<=min(n, K); i++) {
	compute(i);
    }

    // O(512) per query (from 2^18, walk to 2^9 before hitting dp)
    int q;
    cin>>q;
    while (q--) {
	int v, L;
	cin>>v>>L;
	cout<<solve(v,L)<<"\n";
    }
    
    
    return 0;
}


Measured memory_bytes: 10236
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
int GCD(int a, int b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
 
    int main(){
      int n,k;
      cin >> n >> k;
      if(n%k==0) cout << 0 << endl;
      else cout << 1 << endl;
      return 0;}

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

int main(){
	
	int n,m;
	int judge;
	int max=0;
	
	cin >> n >> m ;
	
	int a[n];
	int b[1000]={};
	
	for( int i=0 ; i<n ; i++ ) cin >> a[i] ;
	for( int i=0 ; i<m ; i++ ){
		cin >> judge ;
		for( int j=0 ; j<n ; j++ ){
			if( a[j] <= judge ){
				b[j]++;
				if( max < b[j]) max=b[j];
				break;
			}
		}
	}
	
	for( int i=0 ; i<n ; i++ ){
		if( b[i] == max ){
			cout << i+1 << endl ;
			break;
		}
	}
	
return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) cout << 2 * a - 1 << endl;
	else if (a == b) cout << a + b << endl;
	else cout << 2 * b - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  auto s=readln.chomp.to!(char[]);

  foreach(i; 0..10){
    char[] t;
    foreach(_; 0..3) t~=i+'0';
    if(s[0..($-1)]==t){writeln("Yes"); return;}
    if(s[1..$]==t){writeln("Yes"); return;}
  }

  writeln("No");
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c, d; cin >> a >> b >> c >> d;
	int ans = min(a, d)-max(0LL,d-a-b);
	cout << ans << endl;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll N;cin >> N;
  ll n = N;
  ll f_N = 0;
  while(n!=0){
    f_N += n%10;
    n/=10;
  }
  YesNo(N%f_N == 0);
  return 0;
}


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

const int MAXN = 45;
const int MAXB = 4;
const int INF = 1<<28;

int N;
int dp[MAXN][MAXB];
int P[MAXN], T[MAXN];

int main() {
  while(cin >> N && N) {
    P[0] = 0;
    T[0] = 0;
    for(int i = 0; i < N; ++i) {
      cin >> P[i+1] >> T[i+1];
    }
    P[N+1] = 0;
    T[N+1] = INF;
    N += 2;
    fill(dp[0], dp[MAXN], INF);
    dp[0][0] = 0;
    int stage = 0;
    for(int i = 0; i < N; ++i) {
      for(int k = 0; k < MAXB; ++k) {
        if(dp[i][k] == INF) continue;
        stage = i;
        // 1
        {
          int dist = abs(P[i+1] - P[i]);
          if(k+1 < MAXB && dist*(k+1) <= T[i+1] - T[i]) {
            dp[i+1][k+1] = min(dp[i+1][k+1], dp[i][k] + dist);
          }
        }
        // 2
        {
          int dist = P[i] + P[i+1];
          if(P[i] * (k+1) + P[i+1] <= T[i+1] - T[i]) {
            dp[i+1][1] = min(dp[i+1][1], dp[i][k] + dist);
          }
        }
      }
    }
    int res = INF;
    for(int k = 0; k < MAXB; ++k) {
      res = min(res, dp[N-1][k]);
    }
    if(res != INF) {
      cout << "OK " << res << endl;
    } else {
      cout << "NG " << stage+1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, i=0, j;
  cin >> N;
  int A[N];
  for(j=0;j<N;j++)
    cin >> A[j];
  for(;;){
    for(j=0;j<N;j++){
      if(A[j]%2){
        cout << i << endl;
        return 0;
      }else
        A[j]/=2;
    }
    i++;
  }
}

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

#define ll long long
#define pb push_back
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

const ll mod = 2019;
ll power(ll a, ll n) {
    if(n == 0) return 1;
    else if(n%2 == 0) {
        return power((a%mod*a%mod)%mod, n/2)%mod;
    }
    else return (a%mod * power((a%mod * a%mod), (n-1)/2)%mod)%mod;
}

ll add(ll a, ll b) {
    ll ans = (a%mod + b%mod)%mod;
    return ans;
}

ll mul(ll a, ll b) {
    ll ans = (a%mod * b%mod)%mod;
    return ans;
}

void solve() {
    string s;
    cin >> s;
    ll n = (ll)(s.size());
    ll po = 0LL;
    ll ans = 0LL;
    map<ll, ll> mp;
    mp[0] ++;
    for(ll i = n-1; i>=0; i--) {
        ll dig = s[i] - '0';
        ans = add(ans, mul(power(10LL, po), dig));
//        debug1(ans)
        mp[ans] ++;
        po ++;
    }
    ll out = 0;
    for(auto it: mp) {
        if(it.second > 1) {
            out = (out + ((it.second) * (it.second-1))/2);
        }
    }
    cout << out << '\n';
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << res << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)

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

ll LCM(ll a, ll b)
{
	return a * b / GCD(a, b);
}


int main() {
	int a, b;
	cin >> a >> b;
	pv(LCM(a, b));
	return(0);
}

Measured memory_bytes: 256
<?php
    $c = trim(fgets(STDIN));
    $list = array("a","i","u","e","o");
    $flg = FALSE;
    foreach($list as $val){
        if($val == $c){
            echo "vowel";
            $flg = TRUE;
            break;
        }
    }
    if($flg == FALSE){
        echo "consonant";
    }
?>

Measured memory_bytes: 4604
X,Y = map(int,input().split())
if Y % 2 !=0:
    a = "No"
else:
    t = 2*X-Y/2
    k = Y/2-X
    if int(t)<0 or X<int(t) or int(Y/2)<int(t):
        a = "No"
    elif int(k)<0 or X<int(k) or int(Y/4)<int(k):
        a = "No"
    else:
        a = "Yes"
print(a)

Measured memory_bytes: 9136
#include<stdio.h>
int main(){
	int N,A,B;
	char x[100010];
	scanf("%d%d%d",&N,&A,&B);
	A+=B;
	scanf("%s",x);
	for(int i=0;i<N;i++){
		if(x[i]=='a'){
			A--;
			if(A>=0)printf("Yes\n");
			else printf("No\n");
		}
		else if(x[i]=='b'){
			
			if(A>0&&B>0){printf("Yes\n");A--;B--;}
			
			else printf("No\n");
		}
		else printf("No\n");
	}
	return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N;
  string Arare = "Three";
  for (int i=0; i <N; i++){
    cin >> S;
    if ( S == "Y" ){
      Arare = "Four";
      break;
    }
  }
  cout << Arare;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int dp[100005];
int a[100005];
int n,k;
long long int cost(int i)
{
	if(dp[i]!=-1)
	return dp[i];
	if(i==n-1)
	return 0;
	long long int ans=1000000000;
	for(int j=1;j<=k;j++)
	{
		if(i+j<n)
		ans=min(ans,abs(a[i]-a[i+j])+cost(i+j));
		else
		break;
	}
	return dp[i]=ans;
}
int main()
{
	for(int i=0;i<100005;i++)
	dp[i]=-1;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	cin>>a[i];
	cout<<cost(0);
}

Measured memory_bytes: 6144