akhauriyash/Code-Regression huggingface dataset:
N=int(input())
# 10
# 1 2 3 4

# 11
# 1 2 3 5

# 12
# 1 2 4 5

# 13
# 1 3 4 5

# 14
# 2 3 4 5

#15
#1 2 3 4 5

# X=5のとき
# X*(X-1)//2　と　(X+1)*X//2　の間に答えがある
# 余計な数を一つ引けばいい

# Xを二分探索で決める
def isHigh(x):
  if N<=((x+1)*x)//2:
    return True
  return False
hi=N
lo=0
while abs(hi-lo)>1:
  mid=abs(hi+lo)//2
  if isHigh(mid):
    hi=mid
  else:
    lo=mid
X=hi
sumX=(X+1)*X//2
diff=sumX-N
for i in range(1,X+1):
  if i!=diff:
    print(i)


Measured memory_bytes: 3316
N = int(input())
H = list(map(int,input().split()))

for i in range(N-1):
  if H[N-i-1] < H[N-i-2]:
    H[N-i-2] -= 1
    
f = 0
for i in range(N-1):
  if H[N-i-1] < H[N-i-2]:
    f = 1
    
if f == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;

int mxn = 2e5 + 6;
vector<set<int>> adj(mxn);
vector<int> vis(mxn);

void dfs(int node, int& cnt)
{
	if (!vis[node]) {
		vis[node] = 1;
		cnt++;
	}
	for (int x : adj[node]) {
		if (!vis[x]) dfs(x, cnt);
	}
}

int main()
{
	fastIO;
	int n,m;
	cin >> n >> m;
	for (int i=0; i<m; i++) {
		int u,v;
		cin >> u >> v;
		adj[u].insert(v);
		adj[v].insert(u);
	}
	int ans = 0;
	for (int i=1; i<=n; i++) {
		if (vis[i]) continue;
		int cnt = 0;
		dfs(i, cnt);
		ans = max(ans, cnt);
	}
	cout << ans << '\n';
}	

Measured memory_bytes: 38248
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  int h,w;
  cin >>h >>w;
  
  vector<string> mine(h);
  
  for(int i=0; i<h; i++){
    cin >> mine.at(i);
  }
  
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(mine.at(i).at(j) == '.'){
        char n = '0';
        for(int k=-1; k<=1; k++){
          for(int l=-1; l<=1; l++){
            if(i-k<0 || i-k>=h || j-l<0 || j-l>=w){
              continue;
            }
            else if(mine.at(i-k).at(j-l) == '#'){
              n++;
            }
          }
        }
        mine.at(i).at(j) = n;
      }
    }
  }
      
  for(int i=0; i<h; i++){
    cout << mine.at(i) <<endl;
  }
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main()
{
	string s[3];

	cin >> s[0] >> s[1] >> s[2];

	cout << s[0][0] << s[1][1] << s[2][2] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
const ll INF = (ll)1e18;

ll H, W, V;

ll pos2idx(ll y, ll x) { return y * W + x; }
ll idx2y(ll idx) { return idx / W; }
ll idx2x(ll idx) { return idx % W; }

int main()
{
  std::cin >> H >> W;
  V = H * W;
  std::vector< std::string > grid(H, std::string(W, 'x'));

  for (ll y = 0; y < H; y++) {
    std::cin >> grid[y];
    std::cout << grid[y] << std::endl;
    std::cout << grid[y] << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  ll N;
  cin >> N;

  ll ans = 0;
  for(ll i = 1; i * i < N; i++){
    if(N % i == 0){
      ll v = (N / i - 1);
      if(N % v) ans += v;
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;

int main(){ 
	int K;
	queue<ll> que;
	cin >> K;
	rep(i,9){que.push(i+1);}

	ll x;
	while(true){
		x = que.front(); que.pop();
		K--;
		if(!K)break;
		if(x%10!=0){ que.push(x*10+x%10-1); }
		que.push(x*10+x%10);
		if(x%10!=9){ que.push(x*10+x%10+1); }

		
	}

	cout << x << endl;
}

Measured memory_bytes: 1792
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))

# print(s)

dx = [0, 0, 1, 1, 1, -1, -1, -1]
dy = [1, -1, 0, -1, 1, 0, 1, -1]
t = []

for i in range(h):
    temp = []
    for j in range(w):
        count = 0
        if s[i][j] == '#':
            temp.append('#')
            continue
        for k in range(len(dx)):
            xx = j + dx[k]
            yy = i + dy[k]
            if (xx < 0) or (xx > w - 1) or (yy < 0) or (yy > h - 1):
                continue
            # print(xx, yy)
            if s[yy][xx] == '#':
                count += 1
        temp.append(str(count))
    t.append(temp)
for i in range(h):
    row = ''
    for x in t[i]:
        row += x
    print(row)


Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int N, K;

int main()
{
    ios::sync_with_stdio(false);
    cin >> N >> K;
    vector<double> prob(K + 1);

    for (int i = 1; i <= N; ++i) prob[min(i, K)] += 1.0 / N;

    for (int i = 1; i < K; ++i) prob[min(2*i, K)] += 0.5 * prob[i];

    cout.precision(12);
    cout << prob[K] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <limits>
#include <utility>
#include <bitset>
#include <sstream>
#define ll long long
#define lint long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define INF 1e9

int N;


int main()
{
	cin>>N;
vector<int> h(N);

	rep(i,N){
		cin>>h[i];
	}



	bool endflag = false;
	int ans = 0;
	while (!endflag) {
		int left = 0;
		endflag = true;
		for (int i = 0; i < N; i++) {
			if (h[i] > 0) {
				left = i;
				endflag = false;
				break;
			}
		}

		for (int i = left; i < N; i++) {
			if (h[i] > 0) {
				h[i]--;
			}
			else break;
		}
	
	if(endflag)break;

	ans++;

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
#include <ratio>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 998244353

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int n, k;
    cin >> n >> k;

    vector<int> a(n + 1);

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

    vector<int> dp(n + 1);

    for(int i = 2; i <= n; i++)
    {
        int res = INT_MAX;
        for(int j = 1; j <= k && i - j >= 1; j++)
        {
            res = min(res, abs(a[i] - a[i - j]) + dp[i - j]);
        }
        dp[i] = res;
    }


    cout << dp[n] << "\n";
 
}

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

    int T = 1;
    //cin >> T;

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

    return 0;
}



Measured memory_bytes: 3992
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 
void solve(){
	ll n;
	cin>>n;
	vector<pll> vec(n);
	ll a,b;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		vec[i] = {a,b};
	}
	int pp[2] = {-1,1};
	int qq[2] = {-1,1};
	ll ans = 0;
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++ ){
			ll mn = pp[i]*vec[0].ff + qq[j]*vec[0].ss;
			for(int k =1;k<n;k++){
				ll cur = pp[i]*vec[k].ff + qq[j]*vec[k].ss;
				ans = max(ans,cur - mn);
				mn = min(mn,cur);
			}
		}
	}
	cout<<ans<<endl;
}
 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	ll t;
	// cin>>t;
	t=1;
	while(t--){
		solve();
	}    
    return 0;
}

Measured memory_bytes: 6364
//============================================================================
// Name        : ITP_1_8_D.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;

int main() {
	string str_s, str_p;
	int i,j;
	bool able=false;
	getline(cin,str_s);
	getline(cin,str_p);
	for(i=0; i<(int)str_p.length()-1; ++i) {
		str_s+=str_s[i];
	}
	for(i=0; i<(int)str_s.length()-(int)str_p.length()+1;++i) {
		for(j=0; j<(int)str_p.length(); ++j) {
			if(str_s[i+j]!=str_p[j]) {
				break;
			}
		}
		if(j==(int)str_p.length()) {
			able=true;
		}
	}
	cout << (able?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 3152
n = int(input())
d = {}

for _ in range(n):
  s = input()
  d[s] = d.get(s, 0) + 1 

n = max(d.values())
max_k_list = [kv[0] for kv in d.items() if kv[1] == n]
max_k_list.sort()

for i in max_k_list:
  print(i)


Measured memory_bytes: 32096
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long count = 0; long subcount = 1;
		String[] S = new String[n];
		String s = "0"; String[] s2 = new String[10];
 		for(int i = 0; i < n; i++) {
			s = sc.next();
			for(int j = 0; j < 10; j++)
				s2[j] = s.substring(j,j+1);
		Arrays.sort(s2);
		S[i] = Arrays.toString(s2);
		}
 		Arrays.sort(S);
 		for(int i = 0; i < n-1; i++) {
 			if(S[i].equals(S[i+1])) {
 				subcount++;
 				if(i == n-2) count += subcount*(subcount-1)/2;
 			} else {
 				count += subcount*(subcount-1)/2;
 				subcount = 1;
 			}
 		}
 		System.out.println(count);
	}

}

Measured memory_bytes: 74252
#include <iostream>
#include <algorithm>

bool check(std::string N) {
    for (size_t i=0; i<(N.size()/2); ++i) {
        if (N[i] != N[N.size()-1-i])
            return false;
    }
    return true;
}

int main() {
    int A, B;
    std::cin >> A >> B;
    
    int ans=0;
    for (int i=A; i<=B; ++i) {
        if (check(std::to_string(i))) {
            //std::cout << i << std::endl;
            ans++;
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
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;
    cin >> N;
    vector<int> ans[6];
    for(int i=1; i<5; i++){
        for(int j=5+i; j<=55555; j+=5){
            if(IsPrime(j)){
                ans[i].push_back(j);
            }
        }
    }
    for(int i=1; i<5; i++){
        if(ans[i].size()>=N){
            rep(j,N){
                cout << ans[i][j] << endl;
            }
            break;
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;

int n,a[100005],x[100005],y[100005],s=0; 

int read(){
	int t=1,s=0;
	char c=getchar();
	while((c>'9'||c<'0')&&c!='-')c=getchar();
	if(c=='-')t=-1,c=getchar();
	while(c>='0'&&c<='9')
	s=s*10+c-'0',c=getchar();
	return s*t;
}

int main(void){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		s^=a[i];
	}
	for(int i=1;i<=n;i++){
		int now=s^a[i];
		if(now==a[i]){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int a,b;
	int s=0,t=0;
	
	for(int i=0;i<4;i++){
		cin>>a;
		s+=a;
	}
	for(int i=0;i<4;i++){
		cin>>b;
		t+=b;
	}
	
	cout<<max(s,t)<<endl;
	
}

Measured memory_bytes: 1160
import math


def calc(A, B):
    A, B = max(A, B), min(A, B)
    X = A * B
    rt = int(math.sqrt(X))
    if rt**2 == X:
        rt -= 1
    ans = rt * 2
    if B <= rt:
        ans -= 1
    if rt * (rt+1) >= X:
        ans -= 1
    return ans


def main():
    Q = int(input())
    for _ in range(Q):
        A, B = map(int, input().split())
        ans = calc(A, B)
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <iostream>
using namespace std;
int main()
{

    int i = 0, j = 0, a = 0, b = 0, x = 0, y = 0, num[7] = {0}, c = 0;
    cin >> a >> b;
    for(i = a; i <= b; i++)
    {
        y = i;
        while(y > 0)
        {
            num[c] = y % 10;
            y /= 10;
            c++;
        }
        if(num[0] == num[4] && num[1] == num[3])
        {
            x++;
        }
        for(j = 0; j < 5; j++)
        {
            num[j] = 0;
        }
        c = 0;
    }
    cout << x;


return 0;
}

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

int main()
{
    long long x, count = 0, k, h, t;
    cin >> x;

    if (x <= 11)
    {
        t = (x > 6) ? 2 : 1;
    }
    else
    {
        if (x % 11 == 0)
        {
            k = x / 11;
            t = k * 2;
        }
        else
        {
            k = x / 11;
            h = (x % 11 > 6) ? 2 : 1;
            t = k * 2 + h;
        }
    }
    cout << t << endl;

    return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  int n;
  const int max_n = 1e5;
  int a[max_n + 1];

  cin >> n;
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(i) sum += abs(a[i] - a[i-1]);
    else sum += abs(0 - a[i]);
  }
  sum += abs(a[n-1]);
  // cout << "init = " << sum << endl;

  for(int i = 0; i < n; i++){
    int ans = sum;
    if(i==0) ans = ans + abs(a[1] - 0) - (abs(a[0]) + abs(a[1] - a[0]));
    else if(i == n - 1) ans = ans + abs(a[n-2]) - (abs(a[n-1]) + abs(a[n-1] - a[n-2]));
    else{
      ans = ans + abs(a[i+1] - a[i-1]) - (abs(a[i] - a[i-1]) + abs(a[i+1] - a[i]));
    }
    cout << ans << endl;
  }

  return 0;
}

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

int main(){
  int a , b, c, d;
  cin >> a >> b >> c >> d;
  if((abs(b - a) <= d && abs(c - b) <= d) || abs(c - a) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(1, N):
    if h[i] <= h[i - 1]:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0
ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 63984
/*****************************************************

@author: vichitr

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

#include<bits/stdc++.h>
#define MAX 9223372036854775807
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define ip pair<int, int>

#define loop(i,n) for(int i=0;i<n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
using namespace std;

const ll MOD = 1e9+7;
const ll SZ = 107;
const ll N = 2e5+7;
const ll inf = 1e17;

int pwr(int x, int y)
{
    ll r = 1LL;
    while(y)
    {
        if(y&1)
            r = (r * x) % MOD;
        y >>= 1;
        x = (x * x) % MOD;
    }
    return r % MOD;
}

int inv(int x)
{
    return pow(x, MOD-2);
}
vector<int> adj[N];
bool vis[N];
int c[N], d[N], score, idx;

void solve()
{
    int n,a,b,c,d; cin>>n>>a>>b>>c>>d;
    string s; cin>>s;
    int x = a,y = b;
    
    if(c>d)
    {
    	bool f = 0;
    while(x<=c and y<=d)
    {
    	bool ff = 0; 
    	if(x+2<=c and x+2 != y and s[x+1]=='.')
    		x+=2;
    	else if(x+1<=c and s[x]=='.' and x+1 != y)
    		x++;
    	else if(y+1<=d and s[y]=='.' and y+1 != x)
    		y++;
    	else if(y+2<=d and s[y+1]=='.' and y+2 != x)
    		y+=2;
    	else
    		ff = 1;
    	// cout<<x<<" "<<y<<" "<<c<<" "<<d<<endl;
    	if(x==c and y==d)
    	{
    		f = 1;
    		break;
    	}
    	if(ff){
    		// cout<<"YAY: ";
    		break;
    	}
    	// cout<<x<<" "<<y<<endl;
    }
    if(f)
    	cout<<"Yes";
    else
    	cout<<"No";
    }
    else{
    	bool f = 0;
    while(x<=c and y<=d)
    {
    	bool ff = 0; 
    
    	if(y+2<=d and s[y+1]=='.' and y+2 != x)
    		y+=2;
    	else if(y+1<=d and s[y]=='.' and y+1 != x)
    		y++;
    	else if(x+1<=c and s[x]=='.' and x+1 != y)
    		x++;
    	else if(x+2<=c and x+2 != y and s[x+1]=='.')
    		x+=2;
    	else
    		ff = 1;
    	// cout<<x<<" "<<y<<" "<<c<<" "<<d<<endl;
    	if(x==c and y==d)
    	{
    		f = 1;
    		break;
    	}
    	if(ff){
    		// cout<<"ay: ";
    		break;
    	}
    	// cout<<x<<" "<<y<<endl;
    }
    if(f)
    	cout<<"Yes";
    else
    	cout<<"No";
    }

}

signed main()
{
    fast;
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int t=1;
    // cin >>t;
    while(t--){
        solve();
    }
    return 0;
}

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


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

Measured memory_bytes: 6608
n, w = map(int, input().split())
dp = [[0]*(w+1) for _ in range(n+1)]
for i in list(range(n+1))[1:]:
    wi, vi = map(int, input().split())
    dp[i] = [max(dp[i-1][j], dp[i-1][j-wi]+vi) if j >= wi else dp[i-1][j] for j in range(w+1)]
print(max(dp[-1]))

Measured memory_bytes: 189052
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


N = int(input())
A = list(map(int, input().split()))

min_ = 10**20

B = []
for i in range(N):
    B.append(A[i]-i-1)

B.sort()

Bplus = sum(B)
Bminus = 0
for n in range(N//2):
    sad = Bplus - Bminus
    sad += (2*n-N)*B[n]
    min_ = min(sad, min_)

    Bplus -= B[n]
    Bminus += B[n]

for n in range(N//2, N):
    sad = Bplus - Bminus
    sad += (2*n-N)*B[n-1]
    min_ = min(sad, min_)

    Bplus -= B[n]
    Bminus += B[n]

print(min_)


Measured memory_bytes: 99668
module.exports=function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=0)}([function(t,r,e){"use strict";var n=e(1);e(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,r){t.exports=require("fs")},function(t,r,e){"use strict";var n=e(3),i=e(5);t.exports=function(t){var r=new n(t);i(r)}},function(t,r,e){"use strict";var n=e(4);t.exports=class{constructor(t){var r=t.trim().split(/\s+/g);this.inp=new n(r)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,r,e){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,r,e){"use strict";t.exports=function(t){for(var r=t.in(),e=t.in(),n=t.in(),i=new Array(r),o=0;o<r;o++)i[o]=new Array(r).fill(0);for(var s=0;s<e;s++){var u=t.in()-1,a=t.in()-1;i[u][a]++}for(var c=new Array(r),f=0;f<r;f++)c[f]=new Array(r).fill(0);for(var l=0;l<r;l++)for(var p=0;p<r;p++)c[l][p]=i[l][p],l>0&&(c[l][p]+=c[l-1][p]),p>0&&(c[l][p]+=c[l][p-1]),l>0&&p>0&&(c[l][p]-=c[l-1][p-1]);for(var d=[],v=0;v<n;v++){var h=t.in()-1,y=t.in()-1,b=c[y][y];h>0&&(b+=c[h-1][h-1]-c[y][h-1]-c[h-1][y]),d.push(b)}console.log(d.join("\n"))}}]);

Measured memory_bytes: 77560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>

using namespace std;
typedef pair<int, int> P;


void solve()
{
	vector<string> vec;
	string S, T;
	cin >> S;
	cin >> T;
	if (S.size() < T.size())
	{
		cout << "UNRESTORABLE" << endl;
		return;
	}
	bool isOK = false;
	for (int i = 0; i < S.size(); ++i)
	{
		string sTemp = "";
		for (int j = 0; j < T.size(); ++j)
		{
			if (i + j >= S.size())
			{
				break;
			}
			sTemp += S[i + j];
		}
		if (sTemp.size() != T.size())
		{
			continue;
		}
		bool isSame = true;
		for (int j = 0; j < T.size(); ++j)
		{
			if (sTemp[j] == '?')
			{
				continue;
			}
			if (sTemp[j] != T[j])
			{
				isSame = false;
				break;
			}
		}
		if (isSame)
		{
			string candidate = S;
			for (int j = 0; j < T.size(); ++j)
			{
				candidate[i + j] = T[j];
			}
			vec.push_back(candidate);
			isOK = true;
		}
	}
	if (isOK)
	{
		for (int i = 0; i < vec.size(); ++i)
		{
			for (int j = 0; j < vec[i].size(); ++j)
			{
				if (vec[i][j] == '?')
				{
					vec[i][j] = 'a';
				}
			}
		}
		sort(vec.begin(), vec.end());
		cout << vec[0] << endl;
	}
	else
	{
		cout << "UNRESTORABLE" << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int x;
  cin >> x;
  int x2=x%11;
  int x3=x-x2;
  int ans=0;
  ans+=x3*2/11;
  if(x2<=6&&x2!=0) {
    ans++;
  }
  else if(x2!=0) {
    ans+=2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const int H=301;
const int W=301;
ll a[H][W];
ll_pair A[H*W];
ll h,w,d,q,l,r,ans=0;
ll kyori[H*W]={0};

int main(){
	cin>>h>>w>>d;
	FOR(i,1,h+1){
		FOR(j,1,w+1){
			cin>>a[i][j];
			A[a[i][j]]=make_pair(i,j);

		}
	}
	FOR(i,0,d){
		ll x=i;
		while(x<H*W-d){
			ans+=abs(A[x].first-A[x+d].first);
			ans+=abs(A[x].second-A[x+d].second);
			x+=d;
			kyori[x]=ans;
		}
		ans=0;
	}
	cin>>q;
	FOR(i,0,q){
		cin>>l>>r;
		cout<<kyori[r]-kyori[l]<<endl;
		ans=0;
	}
	
	return 0;
}


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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> v;

    for(int i=A; i<A+K; i++) {
        if(i > B) break;
        v.push_back(i);
    }
    for(int i=B; i>B-K; i--) {
        if(i < A) break;
        v.push_back(i);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    for(int i=0; i < v.size(); i++) cout << v[i] << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
    
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
    
namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}
    
const int MAXN = 2e5 + 10;
    
int n, arr[2][MAXN], l[2][MAXN], r[2][MAXN], ansl, ansr, cnt[MAXN], ans[MAXN];
    
int main() {
    IO::read(n);
    ansr = INT_MAX;
    rep(_, 0, 1) rep(i, 1, n) IO::read(arr[_][i]);
    rep(_, 0, 1) rep(i, 1, n) {
        if (arr[_][i] != arr[_][i - 1]) l[_][arr[_][i]] = i;
        if (arr[_][i] != arr[_][i + 1]) r[_][arr[_][i]] = i;
    }
    rep(i, 1, n) {
        if (l[0][i] && l[1][i]) {
            ansl = max(ansl, r[0][i] - l[1][i] + 1);
            // ansr = min(ansr, abs(l[0][i] - r[1][i]));
            ansr = min(ansr, l[0][i] - r[1][i] + n - 1);
        }
    }
    // printf("l = %d, r = %d\n", ansl, ansr);
    if (ansl > ansr) return puts("No"), 0;
    puts("Yes");
    rep(i, 1, n) {
        ans[(i + ansl - 1) % n + 1] = arr[1][i];
    }
    rep(i, 1, n) printf("%d ", ans[i]);
    return 0;
}

Measured memory_bytes: 9204
// I/O
#include <iostream>
#include <iomanip>

// data structures
#include <queue>
#include <set>
#include <vector>

// manipulations
#include <algorithm>

#define rep(i,n) for(int i=0;i< (n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define for_lowercase(c) for(int c='a';c<='z';++c)
#define for_uppercase(c) for(int c='A';c<='Z';++c)
#define ALL(a) (a).begin(),(a).end()
using LLI = long long int;
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }
using VI  = std::vector<LLI>;
using PI  = std::pair<LLI,LLI>;
using VVI = std::vector<VI>;
using VPI = std::vector<PI>;
template<class T> bool is_odd (T x){ return   x%2 ; }
template<class T> bool is_even(T x){ return !(x%2); }

LLI solve(LLI H,LLI W){
    LLI min = W*H;
    REP(i,H-1){ // cut horizontally
        LLI S1 = i*W;
        LLI h = H-i;
        LLI w = W;
        LLI S2,S3;
        if(is_even(h)){
            S2 = S3 = (h/2) * w;
        }else if(is_even(w)){
            S2 = S3 = h * (w/2);
        }else{
            if(w<h){
                S2 = w * (h/2);
                S3 = S2 + w;
            }else{
                S2 = (w/2) * h;
                S3 = S2 + h;
            }
        }
        LLI res = std::max({S1,S2,S3}) - std::min({S1,S2,S3});
        min = std::min(min,res);
    }
    return min;
}

int main() {
    std::ios::sync_with_stdio(false);
    LLI H,W;
    std::cin >> H >> W;
    std::cout << std::min(solve(H,W),solve(W,H)) << std::endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc127A
{
    class Program
    {
        static void Main(string[] args)
        {
            string A_B = Console.ReadLine();
            string[] c = A_B.Split(' ');
            int A = Convert.ToInt32(c[0]);
            int B = Convert.ToInt32(c[1]);

            if (A>12)
            {
                Console.WriteLine(Convert.ToString(B));
            }
            else if (5 < A && A <= 12)
            {
                Console.WriteLine(Convert.ToString(B / 2));
            }
            else if (A <= 5)
            {
                Console.WriteLine("0");
            }
            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define td(x) x.begin(),x.end()
#define ll long long
#define ld long double
#define pii pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
using namespace std;
 

int32_t main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	cout<<n*n*n<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pie M_PI
#define maxx 2147483647
#define FOR(i,a,b) for(int i=a;i<b;++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
const long long int maxs = 100000000;




int main()
{

    // ios_base::sync_with_stdio(0);
    // cin.tie(NULL);
    // cout.tie(NULL);
    ll a;
    scanf("%lld", &a);
    ll res = a + pow(a, 2) + pow(a, 3);
    cout << res << endl;

}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
string S;

int X[3333],Y[3333];
int Z[6666];

signed main(){
    cin>>N;
    cin>>S;

    int uku=0,ushi=0;
    rep(i,S.size()){
        if(S[i]=='a'){
            Z[i]=uku;
            X[uku++]=i;
        }
        else{
            Z[i]=ushi;
            Y[ushi++]=i;
        }
    }

    vector<string>st;
    int cur=0;
    while(cur<N){
        int nex=cur+1;
        while(nex<N&&max(X[nex-1],Y[nex-1])>min(X[nex],Y[nex]))nex++;
        if(X[cur]<Y[cur]){//ab
            string s;
            int pre=-1;
            for(int i=cur;i<nex;i++){
                if(X[i]<pre)continue;
                s+="ab";
                pre=Y[i];
            }
            st.pb(s);
        }
        else{//ba
            string s="";
            for(int i=cur;i<nex;i++){
                string t;
                rep(j,S.size())if(i<=Z[j]&&Z[j]<nex)t+=S[j];
                chmax(s,t);
            }
            while(st.size()&&st.back()<s)st.pop_back();
            st.pb(s);
        }
        cur=nex;
    }

    string ans;
    rep(i,st.size())ans+=st[i];
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
#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<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}


ll get_mask(int u, int v, vector<int> &parent){
  

  set<int> st1;

  int now = u;
  st1.insert(0);

  while(now != 0){
    
    st1.insert(now);
    now = parent[now];

  }

  now = v;

  while(st1.find(now) == st1.end()){
    now = parent[now];
  }

  int uni_parent = now; // これが共通祖先

  // それぞれから、uni_parentまでの辺を

  vector<int> child;

  now = u;
  while(now != uni_parent){
    child.push_back(now);

    now = parent[now];

  }

  now = v;
  while(now != uni_parent){
    child.push_back(now);

    now = parent[now];
  }

  ll ret = 0;

  for(auto v : child){

    ret += pow(2LL, v);
  }

  return ret;

}


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

  int N;
  cin >> N;
  vector<vector<int>> G(N);

  int a, b;
  rep(i, N-1){
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  // dfsによりparent求める

  vector<int> parent(N);
  rep(i, N) parent[i] = -1;

  queue<int> q;
  q.push(0);
  parent[0] = 0;

  while(!q.empty()){

    int v = q.front();
    q.pop();

    for(auto nv : G[v]){

      if(parent[nv] >= 0) continue;

      parent[nv] = v;
      q.push(nv);
    }
  }

  int M;
  cin >> M;


  vector<ll> masks(M);

  int u, v;
  rep(i, M){
    cin >> u >> v;
    u--;
    v--;
    masks[i] = get_mask(u, v, parent);

  }

  ll ans = 0;
  for(int bit = 0; bit < (1LL << M); bit++){

    int cnt = 0;
    ll all_mask = 0;
    for(int i = 0; i < M; i++){
      if(bit & (1 << i)){
        cnt++;
        all_mask |= masks[i];
      }
    }

    int num = __builtin_popcountll(all_mask);

    if(cnt % 2 == 0){
      
      ans += pow(2, N-1-num);

    }else{
      ans -= pow(2, N-1-num);

    }

  }

  cout << ans << endl;


  

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
using namespace std;

using ll = long long;

#define rep_init(i, init, n) for(int i = (init); i < (n); ++i)
#define rep(i, n) rep_init(i, 0, n)

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

	std::vector<uint64_t> A(N);
	uint64_t X = 0;
	rep(i, N)
	{
		cin >> A[i];
		X ^= A[i];
	}

	rep(i, N)
	{
		cout << (X ^ A[i]);
		if (i < N-1)
		{
			cout << " ";
		}
		else
		{
			cout << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
int n;
vector <string> str;
string mem[15][15];
typedef pair <string,int> P;

string con(string a,string b){
  int K=0;
  for(int i=0;i<a.size();i++){
    int j=i,k=0;
    while(a[j]&&b[k]&&a[j]==b[k]) j++,k++;
    if(!a[j]||!b[k])K=max(K,k);
  }
  return b.substr(K,b.size());
}

string solve(){
  string dp[1<<14][14];
  for(int i=0;i<n;i++) dp[1<<i][i]=str[i];
  
  for(int i=0;i<(1<<n);i++)
    for(int k=0;k<n;k++){
      if(dp[i][k]=="")continue;
      for(int j=0;j<n;j++){
	if((i&(1<<j)))continue;
	string nx=dp[i][k]+mem[k][j];
	int ni=i|1<<j;
	if(!dp[ni][j].size()||
	   nx.size()<dp[ni][j].size()||
	   (nx.size()==dp[ni][j].size()&&dp[ni][j]>nx))dp[ni][j]=nx;
      }
    }

  string res=dp[(1<<n)-1][0];
  for(int i=1;i<n;i++) {
    string a=dp[(1<<n)-1][i];
    if(res.size()>a.size()||(a.size()==res.size()&&res>a)) res=a;
  }
  return res;
}

int main(){
  
  while(cin>>n,n){
    str.resize(n);
    for(int i=0;i<n;i++)cin>>str[i];

    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	if(i!=j&&con(str[i],str[j])==""){
	  str.erase(str.begin()+j);
	  n--;
	  i=-1;
	  break;
	}
    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)mem[i][j]=con(str[i],str[j]);

    cout<<solve()<<endl;
  }

  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    a--, b--, c--, d--;
    FOR (i, a, d - 1) {
        if (s[i] == '#' && s[i + 1] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }
    if (c > d) {
        bool reach = false;
        FOR (i, b, d + 1) {
            if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') reach = true;
        }
        if (reach) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }


    return 0;
}



Measured memory_bytes: 592
#include <stdio.h>
int main(void){
    int n, m, i, j;
    scanf("%d %d", &n, &m);
 
    int A[n][m];
    int b[m];
 
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            int a_ij;
            scanf("%d", &a_ij);
            A[i][j] = a_ij;
        }
    }
 
    for (i = 0; i < m; i++) {
        int b_i;
        scanf("%d", &b_i);
        b[i] =b_i;
    }
 
    for (i = 0; i < n; i++) {
        int c_i = 0;
        for (j = 0; j < m; j++) {
            c_i += A[i][j] * b[j];
        }
        printf("%d\n", c_i);
    }
 
    return 0;
}


Measured memory_bytes: 2132
using System;

class Program {
  static void Main() {
    int n = int.Parse(Console.ReadLine());
    var a = new int[n + 1];
    var p = new int[n + 1];
    int b = 1, cnt = 0;
    var f = true;
    for (int i = 1; i <= n; i++) {
      a[i] = int.Parse(Console.ReadLine());
    }
    while (b != 2) {
      p[b]++;
      if (p[a[b]] > 1) {
        f = false;
        break;
      }
      b = a[b];
      cnt++;
    }
    Console.WriteLine(f ? cnt : -1);
  }
}

Measured memory_bytes: 15164
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N, M, Q;
vector<int>As(Q);
vector<int>Bs(Q);
vector<int>Cs(Q);
vector<int>Ds(Q);
ll ans = 0;
void dfs(vector<int> &A) {
    // 数列の長さが N に達したら打ち切り
    if (A.size() == N) {
        // 処理
        ll cnt = 0;
        for (int i=0; i<Q; i++){
            if (A[Bs[i]-1] - A[As[i]-1] == Cs[i]){
                cnt += Ds[i];
            }
        }
        chmax(ans,cnt);
        return;
    }
    int last;
    if (A.empty())last = 1;
    else last = A.back();

    for (int v = last; v <= M; ++v) {
        A.push_back(v);
        dfs(A);
        A.pop_back();
    }
}

int main() {
    cin >> N >> M >> Q;
    As.resize(Q,0);
    Bs.resize(Q,0);
    Cs.resize(Q,0);
    Ds.resize(Q,0);
    for (int i=0; i<Q; i++){
        int ai, bi, ci, di;
        cin >> ai >> bi >> ci >> di;
        As[i] = ai;
        Bs[i] = bi;
        Cs[i] = ci;
        Ds[i] = di;
    }

    vector<int> A;
    dfs(A);
    cout << ans << endl;
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    int n;
    cin >> n;

    int result = 0, mx = 0;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        result += x;
        if (x > mx) mx = x;
    }
    result = result - mx + mx / 2;
    cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	vector<ll> x(n);
	for( auto &i : x ){
		cin >> i;
	}
	ll ans = INF;
	for( int i = 0; i+k <= n; ++i ){
		ll l = x.at(i);
		ll r = x.at(i+k-1);
		ans = min( ans, r - l + min(abs(l), abs(r)) );
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import math
N , D =map( int,input().split() )
count = 0
Ans_array=[]
for i in  range(N):
    X , Y =map( int,input().split() )
    if math.sqrt( X**2 + Y**2) <= float(D):
        Ans_array.append( math.sqrt( X**2 + Y**2) )
print(len(Ans_array))

Measured memory_bytes: 16900
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>

#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(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    int now = 1;

    REP(i, 10000) {
        now *= K;
        if (N < now) {
            cout << i + 1 << endl;
            return 0;
        }
    }

    return 0;
}


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

int main()
{
    size_t H, W;
    cin >> H >> W;

    vector<size_t> A(H);
    vector<size_t> B(H);
    for (size_t i = 0; i < H; i++)
    {
        cin >> A[i] >> B[i];
    }

    set<pair<size_t, size_t>> goal_start;
    multiset<int> ans;
    for (size_t i = 1; i <= W; i++)
    {
        goal_start.insert(make_pair(i, i));
        ans.insert(0);
    }

    for (size_t i = 0; i < H; i++)
    {
        size_t start = 0;
        size_t right = 0;
        for (set<pair<size_t, size_t>>::iterator itr = goal_start.lower_bound(make_pair(A[i], 0)); itr != goal_start.end() && itr->first <= B[i];)
        {
            size_t goal = itr->first;
            start = itr->second;
            itr = goal_start.erase(itr);
            ans.erase(ans.find(goal - start));
            right = max(right, start);
        }
        if (start > 0 && B[i] < W)
        {
            goal_start.insert(make_pair(B[i] + 1, right));
            ans.insert(B[i] + 1 - right);
        }
        if (ans.empty())
        {
            cout << -1 << endl;
        }
        else
        {
            cout << i + 1 + *ans.begin() << endl;
        }
    }
}


Measured memory_bytes: 28212
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int A = sc.nextInt();

        PriorityQueue<Pair> pq = new PriorityQueue<>((a,b)->a.x-b.x);
        for (int i = 0; i < N; i++) {
            int x = sc.nextInt();
            int h = sc.nextInt();
            pq.offer(new Pair(x, h));
        }

        long totalDamage = 0;
        long ans = 0;
        LinkedList<Pair> q = new LinkedList<>();
        while (!pq.isEmpty()) {
            Pair m = pq.poll();
            int x = m.x;
            long h = m.v;
            while (q.size() > 0 && q.peek().x < x) {
                totalDamage -= q.poll().v;
            }

            if (h >= totalDamage) {
                h -= totalDamage;
                long atackNum = (h+A-1)/A;
                ans += atackNum;
                totalDamage += atackNum*A;
                q.offer(new Pair(x+2*D, atackNum*A));
            }
        }

        System.out.println(ans);
    }

    private static class Pair {
        private final int x;
        private final long v;
        Pair(int x, long v) {
            this.x = x;
            this.v = v;
        }
    }
}


Measured memory_bytes: 102344
fun main(args: Array<String>) {
    val s = readLine()!!
    val (xt, yt) = readLine()!!.split(' ').map { it.toInt() }

    val dx = mutableListOf<Int>()
    val dy = mutableListOf<Int>()
    s.split('T').forEachIndexed { i, sub ->
        if (i % 2 == 0) dx.add(sub.length) else dy.add(sub.length)
    }

    var xs = setOf(dx.first())
    var ys = setOf(0)

    for (d in dx.slice(1 until dx.size)) {
        xs = xs.flatMap { listOf(it - d, it + d) }.toSet()
    }

    for (d in dy) {
        ys = ys.flatMap { listOf(it - d, it + d) }.toSet()
    }

    println(if (xt in xs && yt in ys) "Yes" else "No")
}


Measured memory_bytes: 119304
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os, queue
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)


N = _I()


V = queue.PriorityQueue()
for v in LI():
    V.put(v) 
initial = True
while not V.empty():
    current = V.get()
    new = (current + V.get())/2
    if V.empty():
        V.put(new)
        break

    V.put(new)

print(V.get())


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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    int A,B,ans=0,tmp=0;
    cin >> A >> B;
    int a,b,c,d;

    for(int i = A; i <= B; i++) {
        tmp = i;
        a = tmp / 10000;
        tmp %= 10000;
        b = tmp / 1000;
        tmp %= 1000;
        tmp %= 100;
        c = tmp / 10;
        d = tmp % 10;
        if(a == d && b == c) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int n;
vector<int> v;

ll Solve(int i,int j){
  if(i<0) return 0;
  if( j<(i)/2 || j>(i+2)/2) return -1001001001001001;
  static map<P<int,int>,ll> mp;
  if(mp.find({i,j}) != mp.end()) return mp[{i,j}];
  ll t = 0;
  if(i == 0){
    if(j > 1) return -1001001001001001;
    if(j == 0) return 0;
    return v[i];
  } else {
    t = max(Solve(i-2,j-1)+v[i],Solve(i-1,j));
  }
  return mp[{i,j}] = t;
}

int main(){
  cin >> n;
  v.resize(n);
  cin >> v;
  cout << Solve(n-1,n/2) << endl;
  return 0;
}


Measured memory_bytes: 29032
Imports System

Module Program
    Sub Main(args As String())

        Dim sInputS As String = Console.ReadLine()
        Dim sInputT As String = Console.ReadLine()

        Dim iCount As Integer = 0

        For i = 0 To sInputS.Length - 1
            If sInputT(i) <> sInputS(i) Then
                iCount += 1
            End If
        Next i

        Console.WriteLine(iCount)

    End Sub
End Module


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

long long N;
long long A[2000005];
long long L[2000005];
long long R[2000005];

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		cin >> A[i];
	}

	L[0] = A[0];
	for(long long i = 1; i < N; i++){
		L[i] = max(L[i-1], A[i]);
	}

	R[N-1] = A[N-1];
	for(long long i = N-2; i >= 0; i--){
		R[i] = max(R[i+1], A[i]);
	}

	for(long long i = 0; i < N; i++){
		if(i == 0){
			cout << R[i+1] << endl;
		}else if(i == N-1){
			cout << L[i-1] << endl;
		}else{
			cout << max(L[i-1], R[i+1]) << endl;
		}
	}
}

Measured memory_bytes: 11392
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 1000000001
#define PI 3.14159265358979323846
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	cout << ((1000-(n%1000))%1000) << '\n';
}

Measured memory_bytes: 3652