akhauriyash/Code-Regression huggingface dataset:
/**

Heart beats fast
Colours and promises
How to be brave?
How can I love when I'm afraid to fall?
But watching you stand alone,
All of my doubt suddenly goes away somehow.

One step closer

I have died every day waiting for you
Darling, don't be afraid.
I have loved you for a thousand years
I'll love you for a thousand more

Time stands still
Beauty in all she is
I will be brave
I will not let anything take away
What's standing in front of me
Every breath
Every hour has come to this

One step closer
One step closer

I have died every day waiting for you
Darling, don't be afraid.
I have loved you for a thousand years
I'll love you for a thousand more

And all along I believed I would find you
Time has brought your heart to me
I have loved you for a thousand years
I'll love you for a thousand more

*/

#include <bits/stdc++.h>

using namespace std;

const int N = 120;

long long dp[N][3];

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  
  dp[k][2] = 1;
  dp[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i+1][1] += dp[i][0];
    dp[i+k][2] += dp[i][0];
    
    dp[i+1][0] += dp[i][1];
    
    dp[i+1][0] += dp[i][2];
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += dp[i][1] + dp[i][2];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> a(n, vector<ll>(m)), b(n, vector<ll>(m));
    REP(i, n) REP(j, m) {
        cin >> a[i][j];
        a[i][j]--;
        b[i][a[i][j]] = j;
    }

    ll ans = n;
    vector<ll> idx(n);
    vector<vector<bool>> del(n, vector<bool>(m));
    REP(t, m) {
        vector<ll> cnt(m);
        REP(i, n) cnt[a[i][idx[i]]]++;
        ll ma = 0, mai = -1;
        REP(i, m) if(ma < cnt[i]) ma = cnt[i], mai = i;
        chmin(ans, ma);

        REP(i, n) {
            del[i][b[i][mai]] = true;
            while(idx[i]<m && del[i][idx[i]]) idx[i]++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  for (int i = int(n * 1.1) - n; i <= n; i++) {
    if (int(i * 1.08) == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#define N 3
#define M 9
#define MAX 362880 
static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
typedef struct{
  int f[M];
  int path;
  int none;
}pazzle;
pazzle A[MAX];
int B[MAX];
int head,tail;

int empty(void);
int check(pazzle);
pazzle front(void);
void push(pazzle);
bool isTarget(pazzle);
int bfs(pazzle);

int main(){
  pazzle X;
  int answer,i;
  for(i=0;i<M;i++){
    scanf("%d",&X.f[i]);
    if(X.f[i]==0){
      X.f[i]=M;
      X.none=i;
    }
  }
  answer=bfs(X);
  printf("%d\n",answer);
  return 0;
}

int bfs(pazzle X){
  int sx,sy,tx,ty,i,temp;
  pazzle a,b;
  X.path=0;
  push(X);
  B[check(X)]=1;
  while(!empty()){
    a=front();
    if(isTarget(a))
      return a.path;
    sx=a.none/N;
    sy=a.none%N;
    for(i=0;i<4;i++){
      tx=sx+dx[i];
      ty=sy+dy[i];
      if(tx<0||ty<0||tx>=N||ty>=N)
	continue; 
      b=a;
      temp=b.f[a.none];
      b.f[a.none]=b.f[tx*N+ty];
      b.f[tx*N+ty]=temp;
      b.none=tx*N+ty;
      if(!B[check(b)]){
	B[check(b)]=1;
	b.path++;
	push(b);
      }
    }
  }
  return -1;
}

bool isTarget(pazzle X){
  int i,j;
  for(i=0;i<M;i++){
    if(X.f[i]!=(i+1))
      return false;
  }
  return true;
}

void push(pazzle X){
  A[tail]=X;
  tail=(tail+1)%MAX;
}

pazzle front(void){
  pazzle x;
  x=A[head];
  head=(head+1)%MAX;
  return x;
}

int check(pazzle x){
  int i,j,z,count,result=0;
  for(i=0,z=1;i<M;z*=++i){
    for(j=0,count=0;j<i;j++){
      if(x.f[j]<x.f[i])
	count++;
    }
    result+=count*z;
  }
  return result;
}

int empty(void){
  return head==tail;
}



Measured memory_bytes: 11080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main(){
    string A,B;
    cin>>A>>B;
    if(A.size()<B.size()){
        cout<<"LESS"<<endl;
    }
    else if(B.size()<A.size()){
        cout<<"GREATER"<<endl;
    }
    else{
        if(A==B){
            cout<<"EQUAL"<<endl;
        }
        else{
            bool C;
            rep(i,A.size()){
                if(A[i]==B[i]){
                }
                else{
                    if(A[i]<B[i]){
                        C=false;
                        break;
                    }
                    else{
                        C=true;
                        break;
                    }
                }
            }
            if(C==true){
                cout<<"GREATER"<<endl;
            }
            else{
                cout<<"LESS"<<endl;
            }
        }
    }
}

Measured memory_bytes: 3592
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)


def main():
    n = int(input())
    senkyo = [tuple(map(int,input().split())) for _ in range(n)]
    
    last_t,last_a = senkyo[-1]
    
    def ok(x):
        t = x * last_t
        a = x * last_a
        flag = True
        for i in range(n - 2, -1, -1):
            ti,ai = senkyo[i]
            y = min(t//ti,a//ai)
            t = y * ti
            a = y * ai
            if a == 0 :
                flag = False
                break
        return flag
    
    r = 10 ** 18
    l = 0
    while r - l > 1:
        mid = (r + l)//2
        if ok(mid):
            r = mid
        else:
            l = mid
    
    print(r * (last_a + last_t))

if __name__=='__main__':
    main()




Measured memory_bytes: 3436
#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 pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int n,k,now=1;

signed main() {
    cin >> n >> k;
    rep1(i,INF) {
        now *= k;
        if (now > n) {
            cout << i << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 256
/* 
 * Author: aps
 * Time: 18-06-2019 23:53:49
**/
#include<bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x;}
inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod;}
inline ll power(ll a, ll b) {
    ll x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a) { return power(a, mod - 2);}

const int N = 2005;

int s[N],t[N],dp[N][N];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    int n,m; cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> s[i];
    for(int i=1;i<=m;i++) cin >> t[i];

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            dp[i][j] = add(dp[i][j],dp[i-1][j]);
            dp[i][j] = add(dp[i][j],dp[i][j-1]);
            dp[i][j] = sub(dp[i][j],dp[i-1][j-1]);
            if(s[i] == t[j]){
                dp[i][j] = add(dp[i][j],dp[i-1][j-1]);
                dp[i][j] = add(dp[i][j],1LL);
            }
        }
    }

    cout << (dp[n][m] + 1) % mod << endl;
    return 0;
}


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

long long N, S, A[1 << 19];
long long dp[3009];
long long mod = 998244353;

int main() {
	cin >> N >> S;
	for (int i = 1; i <= N; i++) cin >> A[i];

	dp[0] = 1; long long ans = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = S - A[i]; j >= 0; j--) {
			if (j == 0) dp[j + A[i]] += 1LL * i * dp[j];
			else dp[j + A[i]] += dp[j];
		}
		for (int j = 0; j <= S; j++) dp[j] %= mod;
		ans += 1LL * dp[S];
		ans %= mod;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007

using namespace std;
int main(){
    FAST
    int n,a,b; cin >> n >> a >>b;
    if(a*n < b){
        cout << n*a<<endl;
    }
    else{
        cout << b << endl;
    }
    
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool ok = true;
    rep(i,a){
        if(s[i]=='-'){
            cout << "No" << endl;
            return 0;
        }
    }

    if(s[a]!='-'){
        cout << "No" << endl;
        return 0;
    }

    rep(i,b){
        if(s[i+a+1]=='-'){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <assert.h>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    ll n, l, t;
    cin >> n >> l >> t;
    VL x(n);
    VI w(n);
    REP(i,n) scanf("%lld %d", &x[i], &w[i]);
    ll s = 0, v = 0;
    REP(i,n){
        s += x[i];
        if (w[i] == 1) v++;
        else v--;
    }
    VL y(n);
    REP(i,n){
        if (w[i] == 1) y[i] = (x[i] + t) % l;
        else y[i] = (x[i] + l - (t%l)) % l;
    }
    sort(ALL(y));

    ll cm = (s + v*t) % (l*n);
    if (cm < 0) cm += l*n;

    int ind = -1;
    ll c = 0;
    REP(i,n) c += y[i];

    REP(i,n){
        if (c == cm){
            ind = i;
            break;
        }
        c = (c + l) % (l*n);
    }

    assert(ind != -1);

    REP(i,n){
        printf("%lld\n", y[(ind+i)%n]);
    }

    return 0;
}

Measured memory_bytes: 3200
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define ll long long
#define db double
int book[100005];
int ans[100005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&book[i]);
        ans[book[i]]=i;
    }
    for(int i=1;i<=n;i++)printf("%d ",ans[i]);

    return 0;
}



Measured memory_bytes: 4420
#include<iostream>
#include<algorithm>
#include<vector>
using lint=long long;
using namespace std;

int main()
{	
	lint N;
	lint A[100010]={};
	lint B[100010]={};
	lint asum=0,bsum=0;
	lint chnum=0;
	lint chsum=0;
	lint ans=0;
	vector<lint> v;
	
	cin >> N;
	for(lint i=0;i<N;i++)
	{
		cin >> A[i];
		asum+=A[i];
	}
	for(lint i=0;i<N;i++)
	{
		cin >> B[i];
		bsum+=B[i];
	}
	
	if(asum<bsum)
	{
		cout << -1 << endl;
		return 0;
	}
	
	for(lint i=0;i<N;i++)
	{
		if(A[i]<B[i])
		{
			chnum++;
			chsum+=(B[i]-A[i]);
		}
		else if(A[i]>B[i])v.push_back(A[i]-B[i]);
	}
	
	sort(v.begin(),v.end(),greater<lint>());
	
	for(auto&& i:v)
	{
		if(chsum<=0)break;
		chsum-=i;
		ans++;
	}
	
	cout << ans+chnum << endl;
	return 0;
}

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

long long n, p, pa = 1, pe, tp, ti;

int main() {
    cin >> n >> p;
    if(n == 1) {
        cout << p << endl;
        return 0;
    }
    pe = sqrt(p);
    for(long long i = 2; i <= pe; ++i) {
        if(p % i == 0) {
            long long t = 0;
            tp = p;
            while(tp % i == 0) {
                tp /= i;
                ++t;
            }
            if(t >= n) pa = max(pa, i);
            tp = p;
            ti = p / i;
            t = 0;
            while(tp % ti == 0) {
                tp /= ti;
                ++t;
            }
            if(t >= n) pa = max(pa, ti);
        }
    }
    cout << pa << endl;
}

Measured memory_bytes: 256
str = gets.split
H,W,K = str[0].to_i, str[1].to_i, str[2].to_i

n = []

n[0] = 1+0
n[1] = 1+0
n[2] = 1+1
n[3] = 1+2
n[4] = 1+3+1
n[5] = 1+4+3
n[6] = 1+5+6+1
n[7] = 1+6+10+4

a = Array.new(H+1).map{Array.new(W+1)}

a[0][1] = 1
for x in 2..W
  a[0][x] = 0
end

for x in 1..H
  for y in 1..W
    a[x][y] = a[x-1][y] * (n[y-1] * n[W-y])
  end
  for y in 2..W
    a[x][y-1] += a[x-1][y] * (n[y-2] * n[W-y])
  end
  for y in 1...W
    a[x][y+1] += a[x-1][y] * (n[y-1] * n[W-y-1])
  end
  for y in 1..W
    a[x][y] = a[x][y] % 1000000007
  end
end

puts(a[H][K])

Measured memory_bytes: 1788
use std::io;


fn main() {
    let s = read_one::<String>().chars().collect::<Vec<char>>();
    let mut ans = 0;
    for c in s {
        if c == '+' { ans += 1; }
        if c == '-' { ans -= 1; }
    }
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <iostream>

// Devides an array A[p..r] to A[p..q-1] and A[q+1..r] and return q.
// Result: each element of A[p..q-1] <= A[q] <= each element of A[q+1..r]
// Note that this function always selects an element A[r] as a pivot element.
int partition(int A[], int p, int r) {
    int pivot = A[r];
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (A[j] <= pivot) {
            i++;
            std::swap(A[i], A[j]);
        }
    }
    std::swap(A[i + 1], A[r]);
    return i + 1;
}

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;

    int A[n];
    for (int i = 0; i < n; i++)
        std::cin >> A[i];

    int q = partition(A, 0, n - 1);
    for (int i = 0; i < n; i++) {
        if (0 < i)
            std::cout << " ";
        if (i == q)
            std::cout << "[" << A[i] << "]";
        else
            std::cout << A[i];
    }
    std::cout << std::endl;
}

Measured memory_bytes: 3392
//Bismillahir Rahmanir Rahim
//In the name of Allah
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long  int
int i,j;

main()
{

 string s;
 cin>>s;
 if(s=="ABC") cout<<"ARC"<<endl;
 else cout<<"ABC"<<endl;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;
 
void testCase() {
    ll x;
    cin >> x;
    ll c1 = (x/500);
    x = x % 500;
    ll c2 = (x / 5);
    ll ans = (c1 * 1000 + c2 * 5);
    cout << ans << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

N = int(input())
XY = [[[] for _ in range(10**5 +1)] for __ in range(2)]
for _ in range(N):
    x, y = map(int, input().split())
    XY[0][x].append(y)
    XY[1][y].append(x)

def DFS(i, XorY=0):
    for next in XY[XorY][i]:
        if visited[1-XorY][next]==0:
            visited[1-XorY][next] = 1
            DFS(next, 1-XorY)
            count[1-XorY] += 1

ans = 0
visited = [[0 for _ in range(10**5 +1)] for __ in range(2)]
for i in range(10**5 +1):
    if XY[0][i]!=[] and visited[0][i]==0:
        visited[0][i]=1
        count = [1,0]
        DFS(i)
        ans += count[0]*count[1]
ans -= N

print(ans)

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

int main() {
    int N, M;
    cin >> N >> M;
    int a,b;
    a = 0;
    b = 0;
    if (N >= 2) {
        a = 1;
        for (int i = 1; i <= 2; i++) {
            a = a * (N - i + 1) / i;
        }
    }
    if (M >= 2) {
        b = 1;
        for (int i = 1; i <= 2; i++) {
            b = b * (M - i + 1) / i;
        }
    }
    cout << a+b << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  char s[4];
  int i,a=0,b=0,c=0;
   scanf("%s",s);
   for(i=0;i<3;i++){
      if(s[i]=='a')
         a++;
       if(s[i]=='b')
         b++;
       if(s[i]=='c')
         c++;
    }
   if(a==1&&b==1&&c==1){
      printf("Yes\n");
   }
   else{
		printf("No\n");
   }
  return 0;
}

Measured memory_bytes: 128
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

pub trait BITOperator {
    fn unit() -> Self;
    fn apply(a: &Self, b: &Self) -> Self;
}

pub struct BIT<T: BITOperator> {
    buffer: Vec<T>,
}

impl<T: BITOperator> BIT<T> {
    pub fn new(n: usize) -> BIT<T> {
        let mut buffer = vec![];
        for _ in 0..n {
            buffer.push(T::unit());
        }
        BIT { buffer }
    }

    pub fn update(&mut self, i: usize, v: T) {
        let mut x = i + 1;
        let mut base = 1;
        while x <= self.buffer.len() {
            self.buffer[x - 1] = T::apply(&v, &self.buffer[x - 1]);
            while x & base == 0 {
                base *= 2;
            }
            x += base;
        }
    }

    pub fn query(&self, i: usize) -> T {
        let mut v = T::unit();
        let mut x = i + 1;
        let mut base = 1;
        while x > 0 {
            v = T::apply(&v, &self.buffer[x - 1]);
            while x & base == 0 {
                base *= 2;
            }
            x -= base;
        }
        v
    }
}

impl BITOperator for isize {
    fn unit() -> isize {
        0
    }

    fn apply(a: &isize, b: &isize) -> isize {
        a + b
    }
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let msize = n * (n + 1) / 2;
    let mut l = 0;
    let mut r = INF;
    while r - l > 1 {
        let m = (r + l) / 2;
        let b = a
            .iter()
            .map(|&ai| if ai >= m { 1 } else { -1 })
            .collect::<Vec<isize>>();
        let mut acc_b = vec![0; n + 1];
        for i in 0..n {
            acc_b[i + 1] = acc_b[i] + b[i];
        }
        let acc_b_min = *acc_b.iter().min().unwrap();
        for i in 0..=n {
            acc_b[i] -= acc_b_min;
        }
        let acc_b_max = *acc_b.iter().max().unwrap();

        let mut bit = BIT::new(acc_b_max as usize + 1);
        let mut count = 0;
        for i in 0..=n {
            count += bit.query(acc_b[i] as usize) as usize;
            bit.update(acc_b[i] as usize, 1);
        }
        // dbg!((l, r, m, count));
        if count >= (msize + 1) / 2 {
            l = m;
        } else {
            r = m;
        }
    }
    println!("{}", a.iter().filter(|&&ai| ai <= l).max().unwrap());
}


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

int main() {
  
  string s;
  cin >> s;
  
  if (s == "SUN") cout << 7;
  if (s == "MON") cout << 6;
  if (s == "TUE") cout << 5;
  if (s == "WED") cout << 4;
  if (s == "THU") cout << 3;
  if (s == "FRI") cout << 2;
  if (s == "SAT") cout << 1;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n, q;
int s[200000], t[200000], x[200000];
int d[200000];
vector<int> st[200001];
vector<int> en[200001];
bool dead[200001];

int main() {
    cin >> n >> q;
    rep(i,n) cin >> s[i] >> t[i] >> x[i];
    rep(i,q) cin >> d[i];
    rep(i,n) {
        st[lower_bound(d, d+q, s[i]-x[i]) - d].push_back(i);
        en[lower_bound(d, d+q, t[i]-x[i]) - d].push_back(i);
    }
    priority_queue<pl, vector<pl>, greater<pl>> pque;
    rep(i,q) {
        rep(j,st[i].size()) {
            pque.push(pl(x[st[i][j]], st[i][j]));
        }
        rep(j,en[i].size()) {
            dead[en[i][j]] = true;
        }
        while (!pque.empty() && dead[pque.top().second]) {
            pque.pop();
        } 
        if (pque.size() == 0) {
            cout << -1 << endl;
        } else {
            cout << pque.top().first << endl;
        }
    }
}

Measured memory_bytes: 25448
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define LL long long 
#define LD long double
LD b;
LL a,fff;
int main()
{
	cin>>a;
	for(LD i=0;i<=50000;i+=1)
	{
		if((LL)(i*1.08)==a)
		{
			printf("%.0Lf\n",i);
			fff=1;
			break;
		}
	}
	if(!fff)puts(":(");
	return 0;
}

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

int main(){
    int N;
    string RGB = "RGB", str;
    cin >> N >> str;
    vector<int> A(N);
    for(int i=0; i<N; i++) A[i] = RGB.find(str[i]);
    int S[4001][3] = {0};
    for(int i=0; i<N; i++){
        for(int j=0; j<3; j++) S[i+1][j] += S[i][j];
        S[i+1][A[i]]++;
    }

    int64_t ans = 0;
    for(int i=0; i<N-1; i++) for(int j=i+1; j<N-1; j++) if(A[i] != A[j]){
        for(int k=0; k<3; k++) if(A[i] != k && A[j] != k){
            ans += S[N][k] - S[j+1][k];
            int pos = j+(j-i);
            if(pos < N && A[pos] == k) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


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

class LCA{
public:
	vector<vector<pair<int,int>>>E;
	vector<vector<int>>par;
	vector<int>d1;
	vector<long long>d2;
	int MAX_LOG=22;
	int n;
	LCA(){}
	LCA(int N){
		n=N;
		E=vector<vector<pair<int,int>>>(n);
		par=vector<vector<int>>(MAX_LOG,vector<int>(n));
		d1=vector<int>(n);
		d2=vector<long long>(n);
	}
	void add_edge(int a,int b,int c){
		E[a].push_back(make_pair(c,b));
		E[b].push_back(make_pair(c,a));
	}
	void add_edge(int a,int b){
		E[a].push_back(make_pair(1,b));
		E[b].push_back(make_pair(1,a));
	}
private:
	void dfs(int u,int p,int a,long long b){
		par[0][u]=p;d1[u]=a;d2[u]=b;
		for(auto&v:E[u]){
			if(v.second!=p)dfs(v.second,u,a+1,b+v.first);
		}
	}
	bool flag=false;
	void init(){
		dfs(0,-1,0,0);
		for(int i=1;i<MAX_LOG;i++)for(int j=0;j<n;j++){
			if(par[i-1][j]==-1)par[i][j]=-1;
			else par[i][j]=par[i-1][par[i-1][j]];
		}
		flag=true;
	}
public:
	int lca(int u,int v){
		if(!flag)init();
		if(d1[u]>d1[v])swap(u,v);
		for(int i=0;i<MAX_LOG;i++){
			if((d1[v]-d1[u])>>i&1)v=par[i][v];
		}
		if(u==v)return u;
		for(int i=MAX_LOG-1;i>=0;i--){
			if(par[i][u]!=par[i][v]){
				u=par[i][u];
				v=par[i][v];
			}
		}
		return par[0][u];
	}
	long long dist(int u,int v){
		int l=lca(u,v);
		return d2[u]+d2[v]-d2[l]*2;
	}
};


int a[200000],b[200000],c[200000],d[200000];
struct st{
	int a,b,c,id;
};
vector<st>E[200000];

int cnt[200000];
ll sum[200000];
ll all;


int x[200000],y[200000],u[200000],v[200000];
ll ans[200000];

vector<st>query[200000];

void dfs(int v,int p){
	for(auto s:query[v]){
		ll c=all-sum[s.a]+cnt[s.a]*s.b;
		ans[s.id]+=s.c*c;
	}
	for(auto u:E[v]){
		if(u.a==p)continue;
		cnt[u.b]++;
		sum[u.b]+=u.c;
		all+=u.c;
		dfs(u.a,v);
		cnt[u.b]--;
		sum[u.b]-=u.c;
		all-=u.c;
	}
}

int main(){
	int n,q;cin>>n>>q;
	LCA lca(n);
	rep(i,n-1){
		scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
		a[i]--;b[i]--;
		E[a[i]].push_back({b[i],c[i],d[i]});
		E[b[i]].push_back({a[i],c[i],d[i]});
		lca.add_edge(a[i],b[i]);
	}
	rep(i,q){
		scanf("%d%d%d%d",&x[i],&y[i],&u[i],&v[i]);u[i]--;v[i]--;
		query[u[i]].push_back({x[i],y[i],1,i});
		query[v[i]].push_back({x[i],y[i],1,i});
		query[lca.lca(u[i],v[i])].push_back({x[i],y[i],-2,i});
	}
	dfs(0,-1);
	rep(i,q){
		printf("%lld\n",ans[i]);
	}
}

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

  int n, k;
  double sum = 0, tmp;
  cin >> n >> k;
  double a[n];
  rep(i,n)
  {
    cin >> a[i];
    a[i] = a[i] * (a[i] + 1) / 2 / a[i];
  }
  rep(i,k)
  {
    sum += a[i];
  }
  tmp = sum;
  for (int i = 0; i < n - k; ++i) {
    tmp = tmp - a[i] + a[i+k];
    sum = max(sum, tmp);
  }
  printf("%.7lf", sum);
}


Measured memory_bytes: 1792
//
//  main.cpp
//  ervb
//
//  Created by Kanak Gautam on 21/04/20.
//  Copyright © 2020 Kanak Gautam. All rights reserved.
//
 
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 1000000007
using namespace std;
typedef long long int lli;
typedef long double ld;
priority_queue <lli, vector<lli>, greater<lli> > ti;
vector <lli> p[300005],f(200005,0),b(200005,0),a(200005,0);
map <pair<lli,lli>,lli> mp;
set<pair<lli, lli> > s;
set<lli> st;
map<lli,lli> np,v;
queue<lli> q;
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
lli bpow(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
lli fact(lli i)
{
    f[0]=1;
    for(lli k=1;k<=i;k++)
    {
        (f[k]=f[k-1]*k)%=mod;
    }
    return f[i];
}
lli isprime(lli n)
{
    if(n==1)
        return 0;
    for(lli i=2;i<=sqrt(n);i++)
        if(n%i==0)
            return 0;
    return 1;
}
bool cmp(lli i,lli j)
{
    return p[i].size()<p[j].size();
}
 
/*void sieve()
{
    for(lli i=2;i<=5000000;i++)
    {
        if(b[i]==0)
        {
        for(lli j=2;i*j<=5000000;j++)
        {
            b[i*j]=1;
        }
        }
    }
}*/
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    lli n;cin>>n;
    string s;
    cin>>s;
    lli c=0;
    for(lli i=0;i<s.size();i++)
    {
        if(s[i]=='R')c++;
    }
    lli ans=0;
    for(lli i=0;i<c;i++)
    {
        if(s[i]=='W')
            ans++;
    }
    cout<<ans<<endl;
}


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

char Cb( char a ){
	return a - 32;
}
char Cs( char a ){
	return a + 32;
} 

int main(){
	char a[1200];
	fgets(a, 1200, stdin);
	
	for(int i = 0; a[i] != '\0'; i++){
		if( a[i] >= 'a' && a[i] <= 'z' )
			cout << Cb(a[i]) ;
		else if( a[i] >= 'A' && a[i] <= 'Z' )
			cout << Cs(a[i]) ;
		else 
			cout << a[i] ;
	}	
	return 0;
}

Measured memory_bytes: 1084
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trv(a) cerr<<#a<<":\n";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define mod 1000000007
#define inf 9999999999999999ll

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,r;
    cin>>n>>r;
    if(n>=10)
    {
        cout<<r<<endl;
        return 0;
    }
    cout<<r+100*(10-n)<<"\n";
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in insert
#define sz(v) v.size()
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 5;
void solve(){
    int n; cin>>n;
    double sum=0;
    for(int i = 0; i < n; i++){
        double t;
        cin>>t;
        sum+=1/t;
    }
    cout<<fixed<<setprecision(14)<<1/sum;
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 256
/*
THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define r(i,s,l) for(int i=s;i<l;i++)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<long long,long long>
#define ss second
#define ff first
#define N 2000005
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fast();
    int n;
    cin>>n;
    vector<double> a(n);
  r(i,0,n)
    cin >> a[i];
  double ans= 0.0d;
  r(i,0,n)
  ans += 1.0d/a[i];

  cout << setprecision(8) << 1.0d/ans << endl;
	return 0;
}


Measured memory_bytes: 256
#[derive(Default)]
//NOTE
//declare variables to reduce the number of parameters for dp and dfs etc.
struct Solver {}

impl Solver {
    fn solve(&mut self) {
        let stdin = std::io::stdin();
        let mut scn = Scanner {
            stdin: stdin.lock(),
        };
        let n: usize = scn.read();
        let k: usize = scn.read();
        let a: Vec<usize> = scn.vec(n);
        let mut left = 0;
        for i in k..n {
            if a[left] < a[i] {
                println!("Yes");
            } else {
                println!("No");
            }
            left += 1;
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| {
            let mut solver = Solver::default();
            solver.solve()
        })
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2696
#include <iostream>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	int check[] = {2,4,8,16,32,64};
	if (N == 1) {
		cout << N << endl;
	}
	else {
		for (int i = 5; i >= 0; --i) {
			if (check[i] <= N) {
				cout << check[i] << endl;
				break;
			}
		}
	}

	return 0;
}


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

int main(){
  int s;
  cin >> s;
  vector<int> a(4);
  for (int i=3; i>-1; i--) {
    a[i] = s%10;
    s /= 10;
  }
  for (int i=0; i < (1 << 3); i++) {
    bitset<3> op(i);
    int sum = a[0];
    for (int j=0; j<3; j++) {
      if (op[j]) sum += a[j+1];
      else sum -= a[j+1];
    }
    if (sum == 7) {
      cout << a[0];
      for (int j=0; j<3; j++) {
        if (op[j]) cout << "+";
        else cout << "-";
        cout << a[j+1];
      }
      break;
    }
  }
  cout << "=7" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		long ans=0;
		if(k==0){
			System.out.println(n*n);
			return;
		}
		for(long i=k+1; i<=n; i++){
			ans+=((n)/i)*(i-k);
			if((n%i)-k+1>0){
				ans+=(n%i)-k+1;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23636
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(ll i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N = 2e5 + 5;
const ll OO = 1e15;
using namespace std;
ll n;
ll arr[N];
ll dp[N][3];

ll solve(ll i, ll c) {
    if (i > n) {
        re c ? -OO : 0;
    }
    ll &ret = dp[i][c];
    if (~ret) re ret;
    ret = -OO;
    if (c) {
        ret = max(ret, solve(i + 1, c - 1));
    }
    ret = max(ret, arr[i] + solve(i + 2, c));
    re ret;
}

int main() {
    cin >> n;
    rep(i, 0, n) {
        cin >> arr[i];
    }
    /*rep(i, 0, N) {
        rep(j, 0, 3) {
            dp[i][j] = OO;
        }
    }*/
    clr(dp, -1);
    cout << solve(0, (n & 1) + 1);

}

Measured memory_bytes: 14568
k=int(input())
ama=[0]*(k)
now=7%k
ama[now]+=1
if now==0:
  print(1)
  exit()
for i in range(2,k+1):
  now=(10*now+7)%k
  if ama[now]!=0 and now>0:
    print(-1)
    exit()
  elif now==0:
    print(i)
    exit()
  else:
    ama[now]+=1
    

Measured memory_bytes: 16584
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = read().rstrip().decode()
cnt = 0
ans = 0
for i, ss in enumerate(s):
    if ss == 'W':
        ans += i - cnt
        cnt += 1
print(ans)


Measured memory_bytes: 3376
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s, t;
    cin >> s >> t;

    cout << (t.substr(0, s.size()) == s ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int,int>;

int main(){
	int t;
	cin>>t;
	rep(_, t){
		int n, m, a, b;
		cin>>n>>m>>a>>b;

		ll ans=floor_sum(n, m, a, b);
		cout<<ans<<endl;;
	}
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;

int main() {
    ll n;
    int a, b;
    cin >> n;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            a = i;
            b = n / i;
        }
    }
    cout << SZ(to_string(max(a, b))) << "\n";
}

Measured memory_bytes: 3692
N, Y = map(int, input().split())
res_10000 = res_5000 = res_1000 = -1

for a in range(N+1):
    for b in range(N-a+1):
        c = N - a - b
        total = 10000*a + 5000*b + 1000*c
        if total == Y:
            res_10000 = a
            res_5000 = b
            res_1000 = c

print(str(res_10000) + ' ' + str(res_5000) + ' ' + str(res_1000))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        mp[s]++;
    }
    cout << mp.size() << endl;
}

Measured memory_bytes: 19116
// atcoder - dp - D
#include <bits/stdc++.h>

using namespace std;

const long long N = 100005;

long long n, w, a[N], v[N], dp[N], ans;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> w;
	for (long long i = 0; i < n; i++){
		cin >> a[i] >> v[i];
	}



	for (long long i = 0; i < n; i++) {
		for (long long j = w-a[i]; j >= 0; j--) {
			// cout << a[i] << " " <<v[i] << " " << j << endl;
			dp[j+a[i]] = max(dp[j+a[i]], dp[j]+v[i]);
			// cout << dp[j+a[i]] << endl;
		}
		for (long long i = 0; i <= w; i++){
			// cout << dp[i] << " ";
			ans = max(ans, dp[i]);
		}
		// cout << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "MyDisjointset.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
using namespace std;
typedef pair<int, int> P;
const int INF = 2000000000;
int main() {
	int v, e; cin >> v >> e;
	int m[101][101];
	fill(m[0], m[v], INF);
	for (int i = 0; i < e; i++) {
		int s, t, c; cin >> s >> t >> c;
		m[s][t] = c;
	}
	for (int i = 0; i < v; i++) m[i][i] = 0;
	for (int k = 0; k < v; k++)for (int i = 0; i < v; i++) {
		if (m[i][k] == INF) continue;
		for (int j = 0; j < v; j++) {
			if (m[k][j] == INF) continue;
			m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
		}
	}
	for (int i = 0; i < v; i++) if (m[i][i] < 0) {
		cout << "NEGATIVE CYCLE" << endl; return 0;
	}
	for (int i = 0; i < v; i++)for (int j = 0; j < v; j++) {
		if (m[i][j] == INF) cout << "INF";
		else cout << m[i][j];
		if (j == v - 1) cout << endl;
		else cout << " ";
	}
	return 0;
}

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

using namespace std;

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int all;
    all = h * w;
    int black;
    black = a * w + b * h - a * b;
    int white = all - black;

    cout << white << endl; 

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(llint i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
// lower_boundは二分探索
struct edge { int to, cost; };
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

llint binary_search(vector<int>&s,llint a) {
	llint l = -1;
	llint r = (int)s.size();
	while (r - l > 1) {
		llint mid = l + (r - l) / 2;

		if (s[mid]>=a) r = mid;
		else l = mid;
	}
	return r;
}

int main() {
	map<llint, int> S;
	hei(llint) a(100001,0),x(100001,0);
	S[2] = 1;
	rep(i, 3, 100001) {
		bool a = true;
		rep(j,2, sqrt(i)+1) {
			if (i%j==0)a = false;
		}
		if (a)S[i] = 1;
		if (S[i] && S[(i + 1) / 2])x[i]=1;
		x[i] += x[i - 1];
	}
	int Q;
	cin >> Q;
	hei(int) ans(Q);
	rep(i, 0, Q) {
		int r, l;
		cin >> l >> r;
		ans[i] = x[r] - x[l - 1];
	}
	rep(i, 0, Q)cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 8832
#include<stdio.h>

int main(void)
{
 	int a[10000];
	int n;
	long long int gokei = 0;
	
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		gokei += a[i];
	}
	int min = a[0];
	int max = a[0];
	
	for(int i = 0; i < n; i++){
		if(a[i] < min){
			min = a[i];
		}
		if(a[i] > max){
			max = a[i];
		}
	}
	
	printf("%d %d %lld\n", min, max, gokei);
	
	return 0;
   
}

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

int main() {

	int n; cin >> n;
	bool can = true;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		if (a % 2 != 0) continue;
		if (a % 3 != 0 && a % 5 != 0) can = false;
	}
	if (can) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 3640
n,m=map(int,input().split())
if n>m: m,n=n,m
print(m-2 if n==1 and m>1 else 1 if n==1 else (n-2)*(m-2))
#四隅は4回,その他の端は6回,その他は9回ひっくり返るので(n-2)*(m-2)

Measured memory_bytes: 2940
N=int(input())
DP=[0]*(N+1)
DP[1]=1
six=[]
nine=[]
numbersix=6
while numbersix<=N:
    six.append(numbersix)
    numbersix*=6
numbernine=9
while numbernine<=N:
    nine.append(numbernine)
    numbernine*=9
answers=six+nine

if N<=5:
    print(N)
elif N==6:
    print(1)
else:
    for a in range(2,N+1):
        kotae=[b for b in answers if b<=a]
        kouho=[DP[a-1]+1]
        for z in kotae:
            y=DP[a-z]+1
            kouho.append(y)
        DP[a]=min(kouho)
    print(DP[-1])
    

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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
typedef pair<ll,ll> P;

#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define rrep(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) rep(i,0,n)
#define RREP(i,n) rrep(i,n,0)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  cin >> a >> b;
  cout << (a == b? a * 2: max(a,b) * 2 - 1) << endl;

  return 0;
}


Measured memory_bytes: 256
from math import ceil, floor


def tai(X, p) -> int:
    return sum((X[i] - p) ** 2 for i in range(len(X)))


if __name__ == "__main__":
    N = int(input())
    X = [int(x) for x in input().split(" ")]
    print(min(tai(X, p) for p in range(-1, len(X) + 1000)))

Measured memory_bytes: 3060
K = int(input())
ans = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in ans:
    if len(ans) > K:
        break
    if i%10 == 0:
        ans.append(i*10+i%10)
        ans.append(i*10+i%10+1)
    elif i%10 == 9:
        ans.append(i*10+i%10-1)
        ans.append(i*10+i%10)
    else:
        ans.append(i*10+i%10-1)
        ans.append(i*10+i%10)
        ans.append(i*10+i%10+1)
    
print(ans[K-1])

Measured memory_bytes: 7268
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 10000000000000000


int main(){
	int N;cin>>N;
	int cnt = 0;
	vector<int> P(N);
	for(int i=0;i<N;i++){
		cin>>P[i];
		if(P[i]!=i+1)cnt++;
	}
	if(cnt==0||cnt==2){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	

	
	return 0;
}




Measured memory_bytes: 384