akhauriyash/Code-Regression huggingface dataset:
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));

		long x = Long.parseLong(br.readLine());

		double yokin = 100.0;

		long ans = 0;
		while (yokin < x) {
			yokin += Math.floor(yokin / 100);
			ans++;
		}
		System.out.println(ans);
	}
}


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

const int N = 100005;

int n;
long long a[N], l[N], r[N], ans = 0;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
    }
    l[n] = r[n] = a[n];
    for (int i = n - 1; i >= 0; i--) {
        l[i] = (l[i + 1] + 1) / 2;
        r[i] = r[i + 1];
        l[i] += a[i]; r[i] += a[i];
    }
    if (l[0] > 1) {
        return cout << -1, 0;
    }
    long long cur = 1;
    for (int i = 0; i <= n; i++) {
        ans += cur;
        cur = min(r[i + 1], (cur - a[i]) * 2);
    }
    cout << ans;
}


Measured memory_bytes: 5988
n=int(input())
r=list(map(int,input().split()))
t=0
for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			if r[i]==r[j] or r[j]==r[k] or r[i]==r[k]:continue
			s=[r[i],r[j],r[k]]
			s.sort()
			if s[0]+s[1]>s[2]:
				t+=1
print(t)

Measured memory_bytes: 67528
N=int(input())
l=[]
for i in range(N):
    l.append(int(input()))
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
print(lcm_list(l))

Measured memory_bytes: 5460
import java.util.Scanner;

public class Main {

	/*
	 * 必要なタップ数を求める
	 */
	public static void main(String[] args) {

		/*
		 * Scannerで値取得。
		 */
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		s.close();

		/*
		 * とりあえずa個あって1つあたりa-1個ずつ増えると考えてみる。
		 */

		int count = 0;
		int sum = 0;
		//count:タップの個数、sum:差込口の数
		if (b != 1) {
			//b=1の時、タップがそもそもいらない。
			count++;
			sum = a;
			while (sum < b) {
				count++;
				sum += (a - 1);
			}
		}

		System.out.println(count);

	}

}


Measured memory_bytes: 23892
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    r = int(input())

    print(2 * 3.141592653589 * r)


if __name__ == '__main__':
    main()


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

class UnionFind{
private:
	vector<int> par; //�e
	vector<int> sizes; //�f�[�^�̐�

public:
	UnionFind(int n){ 
		par = vector<int>(n);
		sizes = vector<int>(n);
		for(int i = 0; i < n; i++){
			par[i] = i;
			sizes[i] = 1;
		}
	}
	//�؂̍������߂�
	int find(int x){
		if(par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	//x��y�̑�����W���𕹍�
	void unite(int x,int y){
		x = find(x); //x,y�͊e�f�[�^�̍��m�[�h�𓾂�
		y = find(y);
		if(x == y) return;
		if (sizes[x] < sizes[y]) swap(x, y);
		par[y] = x; //x��y�̐e�ƂȂ�悤�ɘA������
		sizes[x] += sizes[y];
	}
	//x��y�������W���ɑ����邩�ۂ�
	bool same(int x, int y){
		return find(x) == find(y);
	}
	//x��������W���̃f�[�^��
	int size(int x){
		return sizes[find(x)];
	}
};

int main()
{
	int n,m;
	cin >> n >> m;
	vi a(m),b(m);
	rep(i,m){
		cin >> a[i] >> b[i];
		a[i]--,b[i]--;
	}
	UnionFind uni(n);
	vector<ll> ans(m);
	ans[m-1] = (ll)n*(n-1)/2;
	for(int i = m-1; i >= 1; i--){
		ans[i-1] = ans[i];
		if(!uni.same(a[i],b[i])){
			ans[i-1] -= (ll)uni.size(a[i])*uni.size(b[i]);
			uni.unite(a[i],b[i]);
		}
	}
	rep(i,m) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 3712
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
// #define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }
  void solve()
  {
  	int n;
  	cin>>n;
  	vi v(n);
  	forn(i,n)cin>>v[i];
  	i64 ans=0;
  	for1(i,n-1)
  	{
  		if(v[i-1]>v[i])
  		{
  			ans+=v[i-1]-v[i];
  			v[i]=v[i-1];
  		}
  	}

  	cout<<ans;


  }
  
  int main()
  {
ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
    #endif
int t=1;
while(t--)
{
  solve();
}

    return 0;
  }


Measured memory_bytes: 3984
#include<stdio.h>
#include<algorithm>
using namespace std;

int main(){
  int a,b;
  for(int i=1; ;i++){
    scanf("%d %d\n", &a,&b);
    if(a==0 && b==0) break;

    if(a>b) swap(a,b);
    printf("%d %d\n", a,b);
    }
}



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

int main(){
  int N;
  cin>>N;
  int A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A,A+N);
  cout<<A[N/2]-A[N/2-1]<<endl;
}

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

#define int 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 sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a,vm,vvm;
vector<int> v,vv;
vector<pair<int,int>> ans;

signed main() {
    cin >> n;
    rep(i,n) {
        cin >> a;
        if (a < 0) vv.pb(a);
        else v.pb(a);
    }
    sort(all(vv));
    sort(rall(v));
    if (!v.size()) {
        ans.pb(mp(vv[vv.size()-1],vv[vv.size()-2]));
        v.pb(vv[vv.size()-1]-vv[vv.size()-2]);
        vv.pop_back();
        vv.pop_back();
        if (vv.empty()) {
            cout << v[0] << endl;
            for(auto i : ans) cout << i.fi << " " << i.se << endl;
            return 0;
        }
    } else if (!vv.size()) {
        if (v.size() == 2) {
            cout << v[0]-v[1] << endl;
            cout << v[0] << " " << v[1] << endl;
            return 0;
        }
        ans.pb(mp(v[v.size()-1],v[v.size()-2]));
        vv.pb(v[v.size()-1]-v[v.size()-2]);
        v.pop_back();
        v.pop_back();
    }
    vm = v[0];
    vvm = vv[0];

    while(v.size() > 1) {
        ans.pb(mp(vvm,v.back()));
        vvm -= v.back();
        v.pop_back();
    }
    while(vv.size() > 1) {
        ans.pb(mp(vm,vv.back()));
        vm -= vv.back();
        vv.pop_back();
    }
    cout << vm-vvm << endl;
    for(auto i : ans) cout << i.fi << " " << i.se << endl;
    cout << vm << " " << vvm << endl;

}




Measured memory_bytes: 5104
n=int(input())
l=""
for i in range(1,n+1):
    if i % 3==0 or i % 10 == 3 or (i % 100)//10 == 3 or (i % 1000)//100 == 3 or (i % 10000)//1000 == 3:
        l+=" "+str(i)
print(l)


Measured memory_bytes: 5640
import java.util.Scanner;

public class Main {

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

		System.out.println(isSameGroup(x, y));

		sc.close();
	}

	static String isSameGroup(int x, int y) {
		if (x == 2 || y == 2) {
			return "No";
		}

		if ((x % 2 == 1 && x <= 7) || (x % 2 == 0 && x >= 8)) {
			if ((y % 2 == 1 && y <= 7) || (y % 2 == 0 && y >= 8)) {
				return "Yes";
			} else {
				return "No";
			}
		} else if (y == 6 || y == 9 || y == 11) {
			return "Yes";
		} else {
			return "No";
		}
	}

}




Measured memory_bytes: 22996
#include <iostream> // cout, endl, cin
using namespace std;

int main(void)
{
  long long int a, b;
  cin >> a >> b;
  if(a > b) cout << "a > b";
  if(a < b) cout << "a < b";
  if(a == b) cout << "a == b";
  cout << endl;
  return 0;
}


Measured memory_bytes: 3116
local h, w = io.read("*n", "*n", "*l")
local tasks = {}
local len = {}
for i = 1, h do
  s = io.read()
  for j = 1, w do
    local idx = (i - 1) * w + j
    if s:sub(j, j) == "#" then
      len[idx] = 0
      table.insert(tasks, idx)
    else
      len[idx] = 1000000007
    end
  end
end
local done = 0

local function walk(src, dst)
  if len[src] + 1 < len[dst] then
    len[dst] = len[src] + 1
    table.insert(tasks, dst)
  end
end

while done < #tasks do
  done = done + 1
  local idx = tasks[done]
  if w < idx then walk(idx, idx - w) end
  if idx <= (h - 1) * w then walk(idx, idx + w) end
  if 1 < w then
    if idx % w ~= 0 then walk(idx, idx + 1) end
    if idx % w ~= 1 then walk(idx, idx - 1) end
  end
end
local ans = len[1]
for i = 2, h * w do
  ans = math.max(ans, len[i])
end
print(ans)


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

int main(){
  int s;cin >> s;
  int h = s/3600;
  int m = (s/60)%60;
  int ss = (s%3600)%60;
  printf("%d:%d:%d\n",h,m,ss);
  return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define lvi vector<long long>
#define pi pair<int,int>
#define lpi pair<long long ,long long>
#define mp make_pair
#define pb push_back
#define ll long long 
#define faltu ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define mod1 1000000000000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>multiordered_set;
ll int pw(ll int a, ll int b,ll md) {
    if (b == 0) return 1;
    ll int t = pw(a, b / 2,md);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
vector<int> pm;
void prm(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
              prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p]) pm.push_back(p);
}
bool cmp(const pair<ll int,ll int> &a,const pair<ll int,ll int> &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first>b.first;
}
ll int gcd(ll int a,ll int b)
{
    if(!a)return b;
    return gcd(b%a,a);
}
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    for (int i = 2; i < n; i++) 
        if (n % i == 0) 
            return false; 
    return true; 
} 
map<int,int>pa;
int find(int i){
    if(pa[i]==i)return i;
    return pa[i]=find(pa[i]);
}     
void join(int i,int j){
    int a=find(i);
    int b=find(j);
    if(b>=a)pa[b]=a;
    else pa[a]=b;
}               
int ddx[]={-1,-1,-1,0,1,1,1,0};
int ddy[]={-1,0,1,1,1,0,-1,-1};
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int main()
{
    faltu;
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll int n,ans=0;
        cin>>n;
        ll int a[n+1],b[n+1];
        for(ll int i=0;i<n;i++)cin>>a[i];
        memset(b,0ll,sizeof(b));
        b[n-1]=a[n-1];
        for(ll int i=n-2;i>=0;i--){b[i]=a[i]+b[i+1];b[i]%=mod;}
        for(ll int i=0;i<n-1;i++)
        {
            ans+=(a[i]*b[i+1])%mod;
            ans%=mod;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 6776
from heapq import heappush, heappop
class MinCostFlow:
    INF = 10**18

    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap, cost):
        G = self.G
        G[fr].append([to, cap, cost, len(G[to])])
        G[to].append([fr, 0, -cost, len(G[fr])-1])

    def flow(self, s, t, f):
        N = self.N; G = self.G
        INF = MinCostFlow.INF

        res = 0
        H = [0]*N
        prv_v = [0]*N
        prv_e = [0]*N

        while f:
            dist = [INF]*N
            dist[s] = 0
            que = [(0, s)]

            while que:
                c, v = heappop(que)
                if dist[v] < c:
                    continue
                for i, (w, cap, cost, _) in enumerate(G[v]):
                    if cap > 0 and dist[w] > dist[v] + cost + H[v] - H[w]:
                        dist[w] = r = dist[v] + cost + H[v] - H[w]
                        prv_v[w] = v; prv_e[w] = i
                        heappush(que, (r, w))
            if dist[t] == INF:
                return -1

            for i in range(N):
                H[i] += dist[i]

            d = f; v = t
            while v != s:
                d = min(d, G[prv_v[v]][prv_e[v]][1])
                v = prv_v[v]
            f -= d
            res += d * H[t]
            v = t
            while v != s:
                e = G[prv_v[v]][prv_e[v]]
                e[1] -= d
                G[v][e[3]][1] += d
                v = prv_v[v]
        return res

while 1:
    M, W = map(int, input().split())
    if M == W == 0:
        break
    *A, = map(int, input().split())
    *B, = map(int, input().split())
    mcf = MinCostFlow(M+W+2)
    for i in range(M):
        mcf.add_edge(0, i+1, 1, 0)
    for i in range(M):
        for j in range(W):
            d = abs(A[i] - B[j])
            mcf.add_edge(i+1, M+1+j, 1, -d*(d-30)*(d-30))
    for i in range(W):
        mcf.add_edge(M+1+i, M+W+1, 1, 0)
    print(-mcf.flow(0, M+W+1, min(M, W)))


Measured memory_bytes: 5752
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
void fail() {
    cout << 0 << endl;
    exit(0);
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    Int N, M; cin >> N >> M;
    vector<Int> A(N); for (auto &a : A) cin >> a;
    Int x = 1;
    for (auto a : A) {
        x = x / __gcd(x, a) * a;
        if (x > 2 * M) fail();
    }
    for (auto a : A) {
        Int t = x / a;
        if (t % 2 == 0) fail();
    }
    cout << (M - x / 2) / x + 1 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    if(n%1000 == 0) cout << 0 << endl;
    else cout << 1000-(n%1000) << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
int main() {

	int h,a;
	cin>>h>>a;
	if(h%a>0)cout<<h/a+1<<endl;
	else cout<<h/a<<endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
an = [int(i) for i in input().split()]
xn = [0]*n
s = sum(an)

xn[0] = s - 2*sum(an[1::2])
for i in range(1,n):
  xn[i] = 2*an[i-1] - xn[i-1]

xn = map(str, xn)
print(" ".join(xn))

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

int main(){
  int cnt, a, b, x;
  int MAX = 1000000;

  vector<bool> num(MAX);

  for(int i=0; i<MAX; i++) num[i] = true;
  num[0] = false;
  num[1] = false;

  for(int i=2; i<sqrt(MAX); i++){
    if(num[i]){
      for(int j=i*2; j<MAX; j+=i){
	num[j] = false;
      }
    }
  }

  while(true){
    cnt=0;
    cin >> a;
    cin >> b;
    cin >> x;
    if((a|b|x) == 0) break;
    
    for(int i=a; i<MAX; i+=b){
      if(num[i]) cnt++;
      if(cnt == x){
	cout << i << endl;
	break;
      } 
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

bool fc(vector<int> &h, int a, int b, int mid){
  ll co = 0;
  int d = a - b;
  rep(i, h.size()){
    if((ll)h.at(i) < (ll)mid*b) continue;
    int z = h.at(i) - mid*b;
    co += (z+d-1)/d;
  }
  return co <= mid;
}

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> h(n);
  rep(i, n) cin >> h.at(i);
  int ng = 0, ok = 1e9;
  while(ok - ng > 1){
    int mid = (ok + ng)/2;
    if(fc(h, a, b, mid) == true) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
  return 0;
}

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

int main() {
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    vector<int> res;
    vector<int> L(N , 0);
    for (int i = 0; i < N; i++) {
        if (S[i] == 'o') L[i] = i >= C + 1 ? L[i - C - 1] + 1 : 1;
        L[i] = max(i == 0 ? 0 : L[i - 1], L[i]);
    }
    vector<int> R(N, 0);
    for (int i = N - 1; i >= 0; i--) {
        if (S[i] == 'o') R[i] = i + C + 1 < N ? R[i + C + 1] + 1 : 1;
        R[i] = max(R[i], i == N - 1 ? 0 : R[i + 1]);
    }
    // for (int i = 0; i < N; i++) cout << L[i] << " ";
    // cout << endl;
    // for (int i = 0; i < N; i++) cout << R[i] << " ";
    // cout << endl;
    vector<int> bad(N, 0);
    for (int i = 0; i < N; i++) {
        int before = i == 0 ? 0 : L[i - 1];
        int after = i == N - 1 ? 0 : R[i + 1];
        if (before + after < K) res.push_back(i + 1);
        // if (!bad[L[i]]) {
        //     res.push_back(i + 1);
        //     bad[L[i]] = 1;
        // } else if (!res.empty() && L[i] == L[res.back() - 1]) {
        //     res.pop_back();
        // }
        // for (auto v: res) cout << v << " ";
        // cout << endl;
    }
    // vector<int> nxto(N, 0);
    // int cur = N;
    // for (int i = N - 1;i >= 0 ;i--) {
    //     if (S[i] == 'o') {nxto[i] = i; cur = i;}
    //     else nxto[i] = cur;
    // }

    // vector<int> seen(N + 1, 0);
    // deque<int> q;
    // for (int i = 0; i < N; i++) {
    //     if (S[i] == 'x') break;
    //     q.push_back(i);
    //     seen[i] = 1;
    // }

    // while (!q.empty()) {
    //     if (q.size() == 1) res.push_back(q.front() + 1);
    //     deque<int> nxtq;
    //     while (!q.empty()) {
    //         int cur = q.front(); q.pop_front();
    //         if (nxto[cur] == N) continue;
    //         if (!seen[nxto[cur]]) {
    //             seen[nxto[cur]] = 1;
    //             nxtq.push_back(nxto[cur]);
    //         }
    //     }
    // }
    if (res.empty()) cout << endl; 

    for (auto v: res) {
        cout << v << endl;
    }

    return 0;
}

Measured memory_bytes: 4984
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,L;
ll ans;
struct Inter{
	int pos,val,l,r;
	Inter(int _p=0,int _v=0,int _l=0,int _r=0){pos=_p,val=_v,l=_l,r=_r;}
};
struct cmp1{
	bool operator ()(const Inter a,const Inter b)const{
		return a.pos<b.pos;
	}
};
struct cmp2{
	bool operator ()(const Inter a,const Inter b)const{
		return a.val==b.val?a.pos<b.pos:a.val<b.val;
	}
};
set<Inter,cmp1> p;
set<Inter,cmp2> s;
inline ll calc(vector<Inter> &v){
	ll tot=0,sum=0;
	for(int i=0;i+L-1<(int)v.size();++i){
		sum+=v[i].l;
		tot+=sum*v[i+L-1].r;
	}
	return tot;
}
int main(){
	n=read(),L=read();
	for(int i=1;i<=n;++i){
		int x=read();
		Inter zyk(i,x,1,1);
		p.insert(zyk),s.insert(zyk);
	}
	while(!s.empty()){
		int w=s.begin()->val;
		vector<Inter> t;
		while(s.begin()->val==w){
			t.push_back(*s.begin());
			s.erase(s.begin());
		}
		for(int l=0,r=1;l<(int)t.size();l=r++){
			while(r<(int)t.size()&&(--p.find(t[r]))==p.find(t[r-1]))++r;
			int len=r-l,cnt=len/L;
			if(!cnt)continue;
			vector<Inter> myh,zyy;
			myh.insert(myh.begin(),t.begin()+l,t.begin()+r);
			for(auto x:myh){
				p.erase(x);
			}
			ans+=calc(myh);
			for(int i=0;i<cnt;++i){
				zyy.push_back(Inter(myh[0].pos+i,w+1,0,0));
			}
			for(int i=0;i+L-1<(int)myh.size();++i){
				zyy[cnt-((int)myh.size()-i)/L].l+=myh[i].l;
			}
			for(int i=L-1;i<(int)myh.size();++i){
				zyy[(i-L+1)/L].r+=myh[i].r;
			}
			ans-=calc(zyy);
			for(auto x:zyy){
				p.insert(x),s.insert(x);
			}
		}
	}
	printf("%lld\n",ans+n);
	return 0;
}



Measured memory_bytes: 33120
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

ll f(vll a, ll s) {
    ll t = 0;
    rep(i, sz(a) - 1) {
        t += a[i];
        if (t < 0) {
            if (t + a[i + 1] <= 0) {
                s += (1 - t) - a[i + 1];
                a[i + 1] = 1 - t;
            }
        } else {
            if (t + a[i + 1] >= 0) {
                s += a[i + 1] - (-t - 1);
                a[i + 1] = -t - 1;
            }
        }
    }
    return s;
}

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

    int n;
    cin >> n;
    vll a(n), b(n);
    rep(i, n)cin >> a[i];
    b = a;
    ll ans = LLONG_MAX;
    {
        ll s = 0;
        if (a[0] <= 0) {
            s = 1 - a[0];
            a[0] = 1;
        }
        smin(ans, f(a, s));
    }
    {
        ll s = 0;
        if (b[0] >= 0) {
            s = b[0] + 1;
            b[0] = -1;
        }
        smin(ans, f(b, s));
    }
    cout << ans << endl;
}


Measured memory_bytes: 2672
#include<cstdio>
#include<algorithm>
struct Element{
    long long a,b;
    bool operator < (const Element& other)const{
        return a+b<other.a+other.b;
    }
};
Element d[100005];

long long getAnswer(int n){
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        int p = n-i+1;
        if(i%2) ans += d[p].a;
        else ans -= d[p].b;
    }
    return ans;
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++){
        scanf("%lld%lld",&d[i].a,&d[i].b);
    }
    std::sort(d+1,d+1+n);
    long long ans = getAnswer(n);
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
	int N;
		
	while(1){
		int S = 0;
		cin>>N;
		if(N == 0) break;
		for(int i = 1; i * i < N;i++){
			if(N%i == 0){
				S += i;
				S += N/i;
			}
		}
		if(S - N == N) cout<<"perfect number"<<endl;
		else if(S - N > N)cout<<"abundant number"<<endl;
		else if(S - N < N)cout<<"deficient number"<<endl; 
	}
}



Measured memory_bytes: 3072
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = list(reversed(input().strip()))
black = 0
ans = 0

for i, v in enumerate(s):
    if v == 'W':
        continue
    else:
        ans += (i - black)
        black += 1
print(ans)


Measured memory_bytes: 81432
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

const int N=105;

int n,a[N],f[N][N];

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
		{
			f[i][j]=n;
			for (int k=1;k<=n;k++)
				if (j!=k) f[i][j]=std::min(f[i][j],f[i-1][k]+(a[i]!=j));
		}
	int ans=n;
	for (int i=1;i<=n;i++) ans=std::min(ans,f[n][i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  ll A,B;
  cin>>A>>B;
  
  
    int c=A%2;
    int d=B%2;
    if((c==1&&d==0)||(c==0&&d==1))
      cout<<"IMPOSSIBLE"<<endl;
    else
      cout<<(A+B)/2<<endl;
  
  
}

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

using namespace std;

int n,k,i,j,cnt[200005];

int main(){
	scanf("%d%d", &n, &k);
	
	for(i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		cnt[x]++;
	}
	
	vector <int> num;
	
	for(i = 1; i <= n; i++){
		if(cnt[i])
		num.push_back(cnt[i]);
	}
	
	sort(num.begin(), num.end());
	
	int res = 0;
	
	for(i = 0; i < (int)num.size() - k; i++)
	res += num[i];
	
	printf("%d\n", res);
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
int main(){
    int n;
    std::cin >> n;
    VEC(int,a,n);
    VEC(int,b,n);
    VEC(int,c,n);
    sort(all(a));
    sort(all(b));
    sort(all(c));
    ll ans=0;
    rep(i,n){
        ans+=(lb(all(a),b[i])-a.begin())*(c.end()-ub(all(c),b[i]));
    }
    std::cout << ans << std::endl;
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int) x.size())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define makeunique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define endl '\n'

typedef pair<int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<string> vs;

template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }

const double pi = acos(-1.);
const ll inf = 1e18 + 7;
const int N = 3e5 + 17;

int n, m;
ll a[N], dp[N][2];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	dp[0][1] = -inf;
	for (int i = 0; i < n; i++) {
	    if (a[i] & 1) {
	    	if (dp[i][1] != -inf)
	    		dp[i + 1][0] = dp[i][1] + a[i] / 2 + 1;
	    	else dp[i + 1][0] = -inf;
	    	dp[i + 1][1] = max(dp[i][0], dp[i][1]) + a[i] / 2;
	    } else {
			dp[i + 1][0] = max(dp[i][0], dp[i][1]) + a[i] / 2;
			if (a[i])
				dp[i + 1][1] = max(dp[i][1] + (a[i] - 1) / 2 + 1, max(dp[i][1], dp[i][0]) + a[i] / 2 - 1);
			else dp[i + 1][1] = -inf;
	    }

//	    cout << i + 1 << " " << dp[i + 1][0] << " " << dp[i + 1][1] << endl;

	}
	cout << max(dp[n][0], dp[n][1]);
}


Measured memory_bytes: 6016
n,m = gets.split.map(&:to_i)
cakes = []
n.times do
  x,y,z = gets.split.map(&:to_i)
  cakes << [x,y,z]
end

candidates = []
(0..7).each do |i|
  bit = i.to_s(2).rjust(3, "0")
  x, y, z = bit.gsub("0","+").gsub("1","-").chars
  cakes.sort! do |a,b|
    tmp1 = eval("#{x}#{a[0]} + #{y}#{a[1]} + #{z}#{a[2]}")
    tmp2 = eval("#{x}#{b[0]} + #{y}#{b[1]} + #{z}#{b[2]}")
    tmp2 <=> tmp1
  end
  tmp = cakes.take(m).transpose.map do |c|
    c.reduce(0) do |a,e|
      a+=e
    end
  end
  candidates << tmp.reduce(0) {|a,e|a+=e.abs}
end

puts candidates.max


Measured memory_bytes: 5112
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
using namespace std;

int main() {

    int h, w, k;

    cin >> h >> w >> k;

    vector<vector<bool>> tile(h, vector<bool>(w));

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            char ch;
            cin >> ch;

            tile[i][j] = ch == '#' ? true : false;

        }
    }


    int hEnd = 1 << h;
    int wEnd = 1 << w;

    int answer = 0;


    for(int hbit = 0; hbit < hEnd; ++hbit) {


        for(int wbit = 0; wbit < wEnd; ++wbit) {
            vector<vector<bool>> t = tile;

            for(int i = 0; i < h; ++i) {
                if(hbit & (1 << i)) {
                    for(int wi = 0; wi < w; ++wi)
                        t[i][wi] = false;

                }
            }

            for(int j = 0; j < w; ++j) {
                if(wbit & (1 << j)) {
                    for(int hi = 0; hi < h; ++hi)
                        t[hi][j] = false;
                }
            }

            int count = 0;
            for(int i = 0; i < h; ++i)
                for(int j = 0; j < w; ++j)
                    if(t[i][j])
                        count++;

            if(count == k)
                answer++;
        }
    }

    cout << answer << endl;

    return 0;

}

Measured memory_bytes: 3600
s = input()
x = int(s)

y = 2
max_num = 1

for i in range(2, x):
    if i > x:
        break
    z = i
    y = z * z
    for j in range(2, x):
        if y <= x:
            max_num = max(max_num, y)
        else:
            break
        y *= z

print(max_num)

Measured memory_bytes: 9176
import collections
N = int(input())
S = input()

ans=0
for i in range(1, N):
    s = S[:i]
    t = S[i:]
#     print(s, t)
    s1 = set(s)
    t1 = set(t)
#     print(s1, t1)
    c = collections.Counter(s1&t1)
    ans = max(ans, len(c))
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <time.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Segment_Tree{
	private:
	int n;
	vl date;
	ll Query_func(int a,int b,int k,int l,int r){
		if(r<=a||b<=l) return -INF;
		if(a<=l&&r<=b) return date[k];
		int m=(l+r)/2;
		return max(Query_func(a,b,k*2+1,l,m),Query_func(a,b,k*2+2,m,r));
	}
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vl(2*n-1,-INF);
	}
	void Update(int k,ll x){
		k+=n-1;
		date[k]=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=max(date[k*2+1],date[k*2+2]);
		}
	}
	ll Query(int b){
		return Query_func(0,b,0,0,n);
	}
	ll Open(int k){
		return date[n+k-1];
	}
};

ll n;

int main(){
	cin>>n;
	Segment_Tree st(n+1);
	st.Update(0,0);
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		st.Update(x,st.Query(x)+x);
	}
	ll res=0;
	for(int i=1;i<=n;i++) res=max(res,st.Open(i));
	cout<<n*(n+1)/2-res<<endl;
}

Measured memory_bytes: 4924
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  vector<Int> A(N);
  cin>>A;
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  vector<Int> num;
  num.push_back(A[0]);
  Int cur = 0;
  Int ans = 0;
  for(Int i=1;i<N;i++){
    Int a = A[i];
    ans += num[cur++];
    num.push_back(a);
    num.push_back(a);
  }


  cout<<ans<<endl;

  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, q;
  cin >> n;
  int limit = min(1023, n);
  vector<int> v(n+1), w(n+1);
  vector<vector<int>> dp(limit+1, vector<int>(MX));
  for (int i = 1; i <= n; ++i) cin >> v[i] >> w[i];
  for (int i = 1; i <= limit; ++i) {
    for (int j = 1e5; j >= w[i]; --j) {
      dp[i][j] = max(dp[i/2][j], dp[i/2][j-w[i]]+v[i]);
    }
    for (int j = w[i]-1; j >= 0; --j) {
      dp[i][j] = dp[i/2][j];
    }
  }

  cin >> q;
  rep(_, q) {
    int u, l;
    cin >> u >> l;
    vector<int> ids;
    while (u > limit) {
      ids.push_back(u);
      u >>= 1;
    }
    int ans = 0;
    int sz = ids.size();
    rep(t, (1<<sz)) {
      int sv = 0;
      int sw = 0;
      rep(i, sz) {
        if (t & (1<<i)) {
          sv += v[ids[i]];
          sw += w[ids[i]];
        }
      }
      if (sw <= l) {
        ans = max(ans, sv + dp[u][l-sw]);
      }
    }
    cout << ans << endl;
  }
}

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

int main() {
    int h, m, h2, m2, k;
    cin >> h >> m >> h2 >> m2 >> k;
    int a = 60 * h + m;
    int b = 60 * h2+ m2;
    cout << b - a - k << '\n';
    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
int d[31][31],c[500][500],dp[3][31];
int main(){
    int n,cmax,ans=1e9;
    scanf("%d%d",&n,&cmax);
    for(int i=1;i<=cmax;i++){
        for(int j=1;j<=cmax;j++){
            scanf("%d",&d[i][j]);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            scanf("%d",&c[i][j]);
        }
    }
    for(int mod=0;mod<3;mod++){
        for(int cmod=1;cmod<=cmax;cmod++){
            dp[mod][cmod]=0;
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if((i+j)%3==mod)dp[mod][cmod]+=d[c[i][j]][cmod];
                }
            }
        }
    }
    for(int c1=1;c1<=cmax;c1++){
        int d1=dp[1][c1];
        for(int c2=1;c2<=cmax;c2++){
            if(c1==c2)continue;
            int d2=dp[2][c2];
            for(int c3=1;c3<=cmax;c3++){
                if(c1==c3||c2==c3)continue;
                int d3=dp[0][c3];
                if(ans>d1+d2+d3)ans=d1+d2+d3;
            }
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1152
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());
		int k = Integer.parseInt(sc.next());
		
		double []d = new double[300001];
		
		for(int i = 0 ; i <= 300000 ; i++) {
			d[i] = (double)(i+2)/2;
		}
		
		double []sum = new double [n+1];
		sum[0] = 0;
		
		for(int i = 0 ;i < n ;i++) {
			int p = Integer.parseInt(sc.next());
			sum[i+1] = sum[i] + d[p-1];
		}
		double max = 0;
		for(int i = 0 ; i <= n-k ; i++) {
			max = Math.max(sum[k+i] - sum[i], max);
		}
		
		System.out.println(max);
		
	}
}


Measured memory_bytes: 65108
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        double x1 = scan.nextDouble();
        double y1 = scan.nextDouble();
        double x2 = scan.nextDouble();
        double y2 = scan.nextDouble();
        double a;
        double b;

        a = x2 - x1;
        b = y2 - y1;
        double c = Math.sqrt(a * a + b * b);
        System.out.printf("% 8f", c);
    }

}



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

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

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

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


int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size();
    rep(i, 0, n){
        s = s[n-1] + s;
        s.erase(n);
        if(s==t){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long k = sc.nextInt();
		sc.close();

		long count = 0;
		for (long i = k; i <= n + 1; i++) {
			long min = 0;
			long max = 0;
			min = (i - 1) * i / 2 ;
			max = (n * i - min);
			count += (max - min + 1);
			if (count > 1_000_000_007) {
				count = count % 1_000_000_007;
			}
		}
		System.out.println(count);
	}

}


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

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

    map<int, int> m;
    for(int i = 0; i < n - 1; i++){
        int k;
        cin >> k;

        auto itr = m.find(k);
        if(itr == m.end()){
            m.insert(make_pair(k, 1));
        }else{
            m[k]++;
        }
    }

    for(int i = 1; i <= n; i++){
        auto itr = m.find(i);
        if(itr == m.end()){
            cout << 0 << endl;
        }else{
            cout << m[i] << endl;
        }
    }
}

Measured memory_bytes: 12972
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 str[] = br.readLine().split(" ");
        int n = Integer.parseInt(str[0]);
        int m = Integer.parseInt(str[1]);
        int a[][] = new int[n][m];
        int b[] = new int[m];
        int c[] = new int[n];
        for(int i=0;i<n;i++){
            str = br.readLine().split(" ");
            for(int j=0;j<m;j++){
                a[i][j] = Integer.parseInt(str[j]);
            }
        }
        for(int i=0;i<m;i++){
            b[i] = Integer.parseInt(br.readLine());
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                c[i] = c[i] + a[i][j] * b[j];
            }
            System.out.println(c[i]);
        }
    }
}

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

const ll INF = 1LL << 60;
const int MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    cout << H * W - h * W - H * w + h * w << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#define BIG 1000000000
#define BIGNUM 100000
#define S_SIZE 10000
using namespace std;

int linearSearch(int *A,int n,int key) {
	int i = 0;
	A[n] = key;
	while (A[i] != key) i++;
	return n != i;
}

int main() {
	int n;
	int q;
	int S[S_SIZE+1];
	int key;
	int cnt = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &S[i]);

	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d", &key);
		if (linearSearch(S, n, key))
			cnt++;
	}
	
	printf("%d\n", cnt);
}

Measured memory_bytes: 3176