akhauriyash/Code-Regression huggingface dataset:
/*input
6 1 2 2
2 1 1 3 0 2
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
	ios_base::sync_with_stdio(false);
	ll n, m, v, p;
	cin >> n >> m >> v >> p;
	ll a[n];
	for (ll &i : a)
		cin >> i;
	sort(a, a + n, greater<ll>());
	int lo = 0;
	int hi = n - 1;
	while (lo < hi)
	{
		int i = (lo + hi + 1) / 2;
		ll ai = a[i] + m;
		vector<ll>K;
		bool ok = true;
		for (int j = 0; j < n; j++)
		{
			if (j != i)
			{
				if (K.size() < p - 1)
				{
					K.push_back(m);
				}
				else
				{
					if (ai - a[j] < 0)
						ok = false;
					K.push_back(min(m, ai - a[j]));
				}
			}
		}
		if (ok)
		{
			ll kiek = (v - 1) * m;
			for (ll i : K)
				kiek -= i;
			if (kiek > 0)
				ok = false;
		}
		if (ok)
			lo = i;
		else
			hi = i - 1;
	}
	cout << lo + 1 << "\n";
}

Measured memory_bytes: 2916
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        scan.close();

        long ret = solver(str);
        System.out.println(ret);
        return;
    }

    private static long solver(String s) {
        return s.chars().filter(c -> '+' == c).count() - s.chars().filter(c -> '-' == c).count();
    }
}


Measured memory_bytes: 26320
use std::process;
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}
fn main() {
    let s = get!(String);
    
    for i in 0..s.len() {
        if (i+1)%2 == 1 {
            match s.chars().nth(i).unwrap() {
                'R' | 'U' | 'D' => print!(""),
                _ => {println!("No"); process::exit(0)},
            }
        }
        else {
            match s.chars().nth(i).unwrap() {
                'L' | 'U' | 'D' => print!(""),
                _ => {println!("No"); process::exit(0)},
            }
        }
    }
        println!("Yes");

        
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n],sum=0;
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  for(int i=0;i<n-1;i++){
   sum+=a[i+1]-a[i];
  }
  cout << sum<<endl;
}


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

int main(){
	string s;
	cin >> s;
	
	if(s=="Sunny"){
		cout << "Cloudy" <<endl;
	}
	else if (s=="Cloudy"){
		cout << "Rainy" <<endl;
	}
	else{
		cout << "Sunny" <<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def cc(Nb,j):
    ANS = 1
    for i in range(j):
        ANS = ANS * (Nb-i)/(i+1)
    return int(ANS)


def main():
    N, P = map(int, input().split())
    A = list(map(int, input().split()))
    Na = 0
    Nb = 0
    for i in range(N):
        if A[i]%2 == 0:
            Na += 1
        else:
            Nb += 1
    if P==0:
        S = 0
        if Nb==0:
            return 2**Na
        for j in range(0,Nb+1,2):
            S += cc(Nb,j)
        return (2**Na) * S
    else:
        S=0
        if Nb==0:
            return 0
        for j in range(1,Nb+1,2):
            S += cc(Nb,j)
        return (2**Na) * S


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int n,u,k,i,j,v[1000],x[1000][1000];

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    for(j = 0; j < k; j++){
      scanf("%d",&v[i]);
      x[u-1][v[i]-1] = 1;
	 }
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j == 0){
	if(x[i][j] == 1) printf("1");
	else printf("0");
      }
      else{
	if(x[i][j] == 1) printf(" 1");
	else printf(" 0");
      }
    }
    printf("\n");
  }

  return 0;
}
	

Measured memory_bytes: 2748
import math

N, D = map(int,input().split())

XY = [list(map(int, input().split())) for i in range(N)]

count = 0
for l in range(len(XY)):
    distance = math.sqrt(XY[l][0] ** 2 + XY[l][1] ** 2)
    if distance <= D:
        count += 1

print(count)

Measured memory_bytes: 45472
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define nl cout<<"\n";
#define chk(x) cout<<#x<<" : "<<x, nl
#define ll long long int
#define u unsigned
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define ci m(char, ll)
#define ii m(ll, ll)
#define mid(a,b) ((a+b)/2)
#define pb push_back
#define LCM(a,b) ((a*b)/__gcd(x,y))
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

class triplet{
    ll f, s, t;};

vl in(ll n){vl v;ll x;
    f(i,n)
    cin>>x, v.pb(x);
    return v;}
void out(vl v){
    fl(i,v)cout<<i;
}
void out(vl v, char ch){
    fl(i,v)
    cout<<i<<ch;
}

void solve(){
 ll A,B,C;
 cin>>A>>B>>C;
 A+B+C >= 22 ? cout<<"bust" : cout<<"win";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
   return 0;
}

Measured memory_bytes: 3604
function main()
  n,k = parse.(Int,split(readline()))

  n_arr = zeros(n)

  for i in 1:k
    d = readline()
    for n_i in parse.(Int,split(readline()))
      n_arr[n_i] += 1
    end
  end
  println(length(filter(iszero, n_arr)))
end
main()


Measured memory_bytes: 176484
#include <stdio.h>

int main() {

int a,b,r,d;
double f;

    scanf("%d %d\n", &a,&b);
    
  r=a%b;

  d=a/b;

  f=(double)a/(double)b;

    printf("%d %d %f\n",d,r,f);
  

  return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>

int main(void)
{
  int a,b,c,temp;
  
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  
  temp = a;
  a = b;
  b = temp;
  
  temp = a;
  a = c;
  c = temp;
  
  printf("%d %d %d\n",a,b,c);
  
  return 0;
}

Measured memory_bytes: 1712
s = input()
K = int(input())
n = len(s)
t = s[::-1]
if 2*K+1 >= n:
  print(n)
  exit()
dp = [[[0 for i in range(K+1)] for j in range(n+1)] for k in range(n+1)]
if n == 2 and K == 0:
  if s == t:
    print(2)
    exit()
  else:
    print(1)
    exit()
ans = min(2*K+1,n)
for center in range(1,n-1):
  flg = 0
  sf = s[:center]
  sl = t[:n-center-1]
  if s[center] == s[center+1]:
    flg = 1
  sfl = len(sf)
  sll = len(sl)
  for j in range(1,sll+1):
    dp[sfl][j][0] = max(dp[sfl-1][j][0],dp[sfl][j-1][0])
    if sf[-1] != sl[j-1]:
      for k in range(1,K+1):
        dp[sfl][j][k] = max(dp[sfl-1][j-1][k-1]+1,dp[sfl-1][j][k],dp[sfl][j-1][k])
    if sf[-1] == sl[j-1]:
      dp[sfl][j][0] = max(dp[sfl][j][0],dp[sfl-1][j-1][0]+1)
      for k in range(1,K+1):
        dp[sfl][j][k] = max(dp[sfl-1][j-1][k-1]+1,dp[sfl-1][j-1][k]+1,dp[sfl-1][j][k],dp[sfl][j-1][k])
  if flg:
    ans= max(dp[sfl][sll][K]*2+1,dp[sfl][sll-1][K]*2+2,ans)
  elif K > 0:
    ans= max(dp[sfl][sll][K]*2+1,dp[sfl][sll-1][K-1]*2+2,ans)
  else:
    ans= max(dp[sfl][sll][K]*2+1,ans)
print(ans)

Measured memory_bytes: 150408
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
    Scanner scan = new Scanner(System.in);

    int H;
    int N;
    ArrayList<Integer> A = new ArrayList<>();

    Main(){
        H = scan.nextInt();
        N = scan.nextInt();
        for(int i = 0; i < N; i++){
            A.add(scan.nextInt());
        }

        judge(H, A);

        /*
        for(int i = 0; i < N; i++){
            System.out.println(A.get(i));
        }*/
    }

    public void judge(int H, ArrayList<Integer> A){
        for(int i = 0; i < A.size(); i++){
            H -= A.get(i);
        }
        if(H <= 0){System.out.println("Yes");}
        else{System.out.println("No");}
    }

    public static void main(String[] args){
        new Main();
    }
}

Measured memory_bytes: 62668
#include<bits/stdc++.h>
#include<map>
#include<bitset>
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define SORTA(v) sort(v.begin(),v.end())
#define SORTD(v) sort(v.begin(),v.end(),greater<int>())
#define REV(v) reverse(v.begin(),v.end())
#define MAXN 200005
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
typedef long long ll;
typedef long double ld;
using namespace std;

ll BigMod(ll base,ll pow,ll mod)
{
    if(pow==0||base==1)return 1;
    else if(pow==1)return base;
    else if(pow%2)return BigMod(base,pow-1,mod)*base%mod;
    else {ll x=(BigMod(base,pow/2,mod)%mod);x=(x*x)%mod;return x;}
}

ll isprime(ll prime)
{
	ll cnt=0;
	for(int i=2;i*i<=prime;i++)
	{
		if(prime%i==0)return false;
		
	}
	return true;
}

   void DBG() { cerr << "]" << '\n'; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << h;
    if (sizeof...(t)) cerr << ", ";
    DBG(t...);
}
 
#ifdef LOCAL // compile with -DLOCAL
    #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
    #define dbg(...) 0
#endif 

//***************** GRAPH VISITED *****************************************************
const int dx[]={+1,-1,+0,+0};
const int dy[]={+0,+0,+1,-1};
const int f1x[]={+0,+0,+1,-1,-1,+1,-1,+1};   /// Kings Move
const int f1y[]={-1,+1,+0,+0,+1,+1,-1,-1};  /// Kings Move
const int f2x[]={-2, -2, -1, -1,  1,  1,  2,  2};  /// Knights Move
const int f2y[]={-1,  1, -2,  2, -2,  2, -1,  1}; /// Knights Move

const int maX=1e3+10;
ll vis[maX][maX];
ll n,m;
void DFS(ll x, ll y)
{
	cout<<x<<' '<<y<<endl;
	vis[x][y]=1;
	
	for(ll i=0;i<4;i++)
	{
		ll d=x+dx[i];
		ll dd=y+dy[i];
		
		if(d>=1 && d<=n && dd>=1 && dd<=m && vis[d][dd] !=1) DFS(d,dd);
	}
   	
	for(ll i=x;i<=n;i++)if(vis[i][y] ==0) DFS(i,y);
	for(ll i=x-1;i>=1;i--)if(vis[i][y]==0)DFS(i,y);
	for(ll i=y;i<=m;i++)if(vis[x][i]==0)DFS(x,i);
	for(ll i=y-1;i>=1;i--)if(vis[x][i]==0)DFS(x,i);
	 
 
	
}

void solve()
{
    ll n,i,j,cc=0,l,r;
    cin>>l>>r;
    if(l==r){
        cout<<0<<endl;
        return;
    }
    j=l^r;
    while(j){
        cc++;
        j >>=1;
    }
    ll ans=0;
    while(cc){
        ans<<=1;
        ans++;
        cc--;
    }
    cout<<ans<<endl;
}

 
//**********************************MAIN_FUNCTION ************************************************************
int main( ) {
 
      ll n,m,i,j,k,len=0,e,p,q,a,b,c,d;
    string str;
    int t;
     ll cnt=0;
       cin>>str;
       for(i=0;i<str.size();i++)
       {
       	 cnt+=str[i]-'0';
       	  
	   }  
	   if(cnt%9)cout<<"No\n";
	   else cout<<"Yes\n";
      
	return 0;
}
 

Measured memory_bytes: 3732
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            if (N % 2 == 0) {
                System.out.println(N);
            } else {
                System.out.println(2 * N);
            }
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    map<int,int> cnt;
    int ans=0;
    rep(i,n){
        int a;
        cin >> a;
        cnt[a]++;
    }
    for(auto c: cnt){
        if(c.second%2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4864
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    printf("%.8lf\n", sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
}


Measured memory_bytes: 3216
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 2e5 + 5;
const long long mod = 998244353 ;
long long dat[maxn << 2], cov[maxn << 2];
long long a[maxn],n,k,l[12],r[12];
void inline pushup(int p)
{
    dat[p] = dat[p << 1] + dat[p << 1 | 1];
}
void build(int p, int l, int r)
{ //建树
    dat[p] = cov[p] = 0;
    if (l == r)
    {
        dat[p] = a[l];
        return;
    }
    int mid = l + r >> 1;
    build(p << 1, l, mid);
    build(p << 1 | 1, mid + 1, r);
    pushup(p);
}
void pushdown(int p, int l, int r)
{ //标记下放
    if (cov[p])
    {
        int mid = l + r >> 1;
        cov[p << 1] = (cov[p << 1] + cov[p])%mod;
        dat[p << 1] = (dat[p << 1] + cov[p])%mod;
        cov[p << 1 | 1] = (cov[p << 1 | 1] + cov[p])%mod;
        dat[p << 1|1] = (dat[p << 1|1] + cov[p]) % mod;
        cov[p] = 0;
    }
}
void change(int p, int l, int r, int ql, int qr, int x)
{ //区间修改
    if (ql <= l && r <= qr)
    {
        dat[p] = (dat[p]+x)%mod;
        cov[p] = (cov[p]+x)%mod;
        return;
    }
    pushdown(p, l, r);
    int mid = l + r >> 1;
    if (ql <= mid)
        change(p << 1, l, mid, ql, qr, x);
    if (qr > mid)
        change(p << 1 | 1, mid + 1, r, ql, qr, x);
    pushup(p);
}

long long ask(int p, int l, int r, int x)
{ //单点查询
    if (l == r)
        return dat[p];
    pushdown(p, l, r);
    int mid = (l + r) >> 1;
    if (x <= mid)
        return ask(p << 1, l, mid, x);
    else
        return ask(p << 1 | 1, mid + 1, r, x);
}

int main()
{
    scanf("%lld%lld", &n,&k);
    for (int i = 0; i < k; i++)
        scanf("%lld%lld",l+i,r+i);
    a[1]=1;
    build(1,1,n);
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < k; j++)
        {
            if(i+l[j]>n)
                continue;
            // printf("%lld %lld %lld\n", i + l[j], min(n, i + r[j]), ask(1, 1, n, i));
            change(1,1,n,i+l[j],min(n,i+r[j]),ask(1,1,n,i));
        }
    }
    printf("%lld\n",ask(1,1,n,n));
    return 0;
}


Measured memory_bytes: 9920
#include<iostream>
//#include <cmath>
#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
#define FOR(i,a,n) for(ll i=(a);i<(n);++i)
#define ROF(i,a,n) for(int i=(a);i>(n);--i)

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
 //   freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    ll k;cin>>k;
    ll n=0;ll f;
    FOR(i,0,k){
        n=10*n+7;
        n=n%k;
        if(n==0){
            cout<<i+1;
            return 0;
        }
    }
   // cout<<f;
    cout<<-1;
    return 0;
}

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

int main() {
	int n, h[20];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int ans = 0;
	int maxH = 0;
	for (int i = 0; i < n; i++) {
		if (h[i] >= maxH) {
			maxH = h[i];
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	var m float64

	fmt.Scan(&n)
	fmt.Scan(&m)
	arr := make([]float64, n)
	total := 0.0
	for i := range arr {
		fmt.Scan(&arr[i])
		total += arr[i]
	}

	ok := total * (1.0 / (4.0 * m))

	cnt := 0
	for _, e := range arr {
		if e >= ok {
			cnt++
		}
	}
	if cnt >= int(m) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
fun main() {
    println(solve())
}

val solve: () -> String = {
    if (readLine()!!.contains('7')) "Yes" else "No"
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun Any?.alsoPrintln() = also { println(this) }

Measured memory_bytes: 35776
import numpy as np

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

X = int(input())
prime = np.array(primes(200000))
if sum(prime == X):
    ans = X
else:
    idx = np.array(np.where(prime > X))
    idx = idx[0]
    ans = prime[idx[0]]
print(ans)

Measured memory_bytes: 23464
N = int(input())
XYH = [[int(i) for i in input().split()] for j in range(N)]
search = 0
while XYH[search][2] == 0:
    search += 1

for X in range(101):
    for Y in range(101):
        H = XYH[search][2] + abs(X-XYH[search][0]) + abs(Y-XYH[search][1])
        for x,y,h in XYH:
               if h != max(H - abs(X-x) -abs(Y-y),0):
                    break
        else:
            print(X,Y,H)
            exit()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    
        var sc = new Scanner(System.in);
    
        int l = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        int ans = 0;
        for(int i = l; i <= r; i++){
            if(i%d == 0) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35612
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N; cin >> N;
    if(N%2==0) cout << N << endl;
    else cout << N*2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

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

        String s = sc.next();
        char[] c = new char[s.length()];
        for(int i = 0; i < s.length(); i++){
            c[i] = s.charAt(i);
        }
        int K = sc.nextInt();
        sc.close();
    
        int index = 0;
        while(index < s.length()){
            char target = c[index];
            if(target != 'a'){
                if(diff(target) <= K){
                    c[index] = 'a';
                    K -= diff(target);
                } 
            }
            index++;
        }
        if(K != 0){
            c[s.length()-1] += (K%26);
        }
        for(int i = 0; i < s.length(); i++){
            System.out.print(c[i]);
        }
    }
    static int diff(char c){
        return 26 - c + 'a';
    }
}

Measured memory_bytes: 35848
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		Scanner scan = new Scanner(System.in);
		while(true)
		{
			int n = scan.nextInt();
			int p = scan.nextInt();
			if(p == 0) return;
			
			int[] inventory = new int[n];
			int whoseturn = -1;
			
			int startp = p;
			
//			inventory[0] = p;
//			p = 0;
			
			while(true)
			{
				whoseturn += 1;
				whoseturn = whoseturn%n;
//				if(whoseturn < 0)whoseturn += n;
//				System.out.println("Can " + whoseturn + "'s turn! Pool: " + p);
				
				if(p > 0)
				{
					p -= 1;
					inventory[whoseturn] += 1;
					
					if(inventory[whoseturn] == startp)
					{
//						System.out.println(p + ", start " + startp);
						System.out.println(whoseturn);
						break;
					}
				}
				else
				{
					p += inventory[whoseturn];
					inventory[whoseturn] = 0;
				}
				
				
			}
		}


	}

}



Measured memory_bytes: 26772
#include <iostream>
#include <string>



int main() {
	int N;
	bool contains = false;
	std::cin >> N;

	std::string str = std::to_string(N);

	for (char c : str) {
		if (c == '7') {
			contains = true;
		}
	}

	if (contains) {
		std::cout << "Yes" << std::endl;
	} else {
		std::cout << "No" << std::endl;
	}
}





Measured memory_bytes: 3696
def gn(n,k):
    k -= 1
    r = k+2*n+n//2 - (1 + 2*k + 2*n)
    if r < 0:
        print(-1)
        return
    print(k+1, 2*n+k, 3*n+k)
    n-=1
    k+=1
    for i in range(1, n+1):
        x = i
        y = n+(i-((n+1)//2)+n)%n+1
        print(k+x, k+y, 2*k+x+y+r)
def kn(n,k):
    k -= 1
    r = k+2*n+(n+1)//2 - (1 + 2*k + 2*n)
    if r < 0:
        print(-1)
        return
    for i in range(1, n+1):
        x = i
        y = n+(i-((n+1)//2)+n)%n+1
        print(k+x, k+y, 2*k+x+y+r)

N, K = map(int, input().split())
if N%2:
    kn(N,K)
else:
    gn(N,K)


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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  each(x,vec) is >> x;
  return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i,vec.size()) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
  rep(i,vec.size()) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}

ll solve() {
  ll n; cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  if (a == b) return 0;
  ll ans = 0, mn = linf;
  rep(i, n) ans += b[i];
  rep(i, n) if (a[i] > b[i]) chmin(mn, b[i]);
  if (mn < linf) ans -= mn;
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << solve() << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N,K,count=0,check=0;
  cin>>N>>K;
  vector<ll> A(0);
  unordered_map<ll,ll> mp;
  for(ll i=0;i<N;i++){
    ll a;
    cin>>a;
    if(mp[a]==0){check++;A.push_back(a);}
    mp[a]++;
  }
  ll d=A.size();
  if(check<=K){cout<<0<<endl;return 0;}
  for(ll i=1;i<=N;i++){
    ll rock=0;
    for(ll j=0;j<d;j++){
      if(mp[A.at(j)]==i){mp[A.at(j)]=0;count+=i;check--;}
      if(K>=check){rock=1;break;}
    }
    if(rock==1){break;}
  }
  cout<<count<<endl;
}

Measured memory_bytes: 10044
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool ok = true;
    REP(i, 0, n) {
        int a;
        cin >> a;
        if (!(a % 2 != 0 || (a % 3 == 0 || a % 5 == 0))) {
            ok = false;
        }
    }
    cout << (ok ? "APPROVED" : "DENIED") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<string>
#include<utility>
using namespace std;
typedef pair<string,int> P;
const string S("01234567");
char arr[9];
map<string,int> obj;
inline string swapno(string s,int i,int j)
{
	char mid;
	string re(s);
	mid=re[i];
	re[i]=re[j];
	re[j]=mid;
	return re;
}
void bfs()
{
	queue<P> que;
	string re;
	int num=1,n;
	que.push(make_pair(S,0));
	obj.insert(make_pair(S,0));
	P mid;
	while(!que.empty())
	{
		mid=que.front();
		que.pop();
		n=mid.first.find("0");
		if(n-1>3||(n-1>=0&&n<=3))
		{
			re=swapno(mid.first,n,n-1);
			if(!obj.count(re))
			{
				que.push(P(re,mid.second+1));
				obj.insert(P(re,mid.second+1));
			}
		}
		if(n+1<=3||(n+1<=7&&n>=4))
		{
			re=swapno(mid.first,n,n+1);			
			if(!obj.count(re))
			{
				que.push(P(re,mid.second+1));
				obj.insert(P(re,mid.second+1));
			}
		}
		
		if(n+4<=7)
		{
			re=swapno(mid.first,n,n+4);
			if(!obj.count(re))
			{
				que.push(P(re,mid.second+1));
				obj.insert(P(re,mid.second+1));
			}
		}
		if(n-4>=0)
		{	
			re=swapno(mid.first,n,n-4);
			if(!obj.count(re))
			{
				que.push(P(re,mid.second+1));
				obj.insert(P(re,mid.second+1));
			}
		}
	}
}
int main()
{
	int i;
	bfs();
	while(scanf("%c %c %c %c %c %c %c %c",&arr[0],&arr[1],&arr[2],&arr[3],&arr[4],&arr[5],&arr[6],&arr[7])!=EOF)
	{
		getchar();
		int num;
		string no1=arr;
		printf("%d\n",obj[no1]);
	}
	return 0;
} 


Measured memory_bytes: 5536
while True:
    n = int(input())

    if n == 0:
        break

    dp = []

    for _ in range(n):
        if len(dp) == 0:
            dp.append(int(input()))
        else:
            x = int(input())
            dp.append(max(dp[-1] + x, x))

    print(max(dp))

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



int main(){
    ll A, B, C, K; cin >> A >> B >> C >> K;
    if(K < A) cout << K << endl;
    else if(K <= A+B) cout << A << endl;
    else {
        ll temp = K - A - B;
        cout << A - temp << endl;
    } 


}

Measured memory_bytes: 3624
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
    	s: String
    }
    
    println!("{}", if s.contains("A") && s.contains("B") { "Yes" } else { "No" });
}

Measured memory_bytes: 4352
#include<stdio.h>
#define MAX 100000
#define NUM 1000000001

struct Card{
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = NUM;
  i = j = 0;
  for ( k = left; k < right; k++ )
    {
      if ( L[i].value <= R[j].value )
        {
          A[k] = L[i++];
        } else {
        A[k] = R[j++];
      }
    }
}

void mergeSort(struct Card A[], int n, int left, int right ){
  int mid;
  if ( left+1 < right )
    {
      mid = (left + right)/2;
      mergeSort(A, n, left, mid);
      mergeSort(A, n, mid, right);
      merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ )
    {
      if ( A[j].value <= x.value )
        {
          i++;
          t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
  t = A[i+1]; A[i+1] = A[r]; A[r] = t;

  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r){
  int q;
  if ( p < r )
{
    q = partition(A, n, p, r);
    quickSort(A, n, p, q - 1);
    quickSort(A, n, q + 1, r);
  }
}

int main(){
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char COM[10];
  int stable = 1;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ )
 {
    scanf("%s %d", COM, &v);
    A[i].suit = B[i].suit = COM[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n-1);

  for ( i = 0; i < n; i++ )
{
    if ( A[i].suit != B[i].suit ) stable = 0;
  }

  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ )
    {
    printf("%c %d\n", B[i].suit, B[i].value);
  }
  return 0;
}

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

using namespace std;

bool cross(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
	double ab=(y1-y2)/(x1-x2)*(x3-x1)+y1, cd=(y1-y2)/(x1-x2)*(x4-x1)+y1;
	if ((ab>y3&&cd>y4)||(ab<y3&&cd<y4)) return false;
	return true;
}

int main() {
	double x1, x2, x3, y1, y2, y3, xp ,yp;
	while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
		double xm = (x1+x2+x3)/3, ym = (y1+y2+y3)/3;
		if (cross(x1,y1,x2,y2,xm,ym,xp,yp)||cross(x2,y2,x3,y3,xm,ym,xp,yp)||cross(x3,y3,x1,y1,xm,ym,xp,yp)) {
			cout << "NO" << endl;
		} else {
			cout << "YES" << endl;
		}
	}
	return 0;
}

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

int main(void){
  char str[65536],sub[65536],subsub[64];
  int i,j,k,n;
  int count,now;
  while(scanf("%d",&n) && n){
    scanf("%s",str);
    for(i=0;i<n;i++){
      strcpy(sub,"\0");
      for(j=0;j<strlen(str);j++){
	if(j==0){
	  count=1;
	  now=str[j]-'0';
	  continue;
	}
	if(str[j-1]!=str[j]){
	  sprintf(subsub,"%d%d",count,now);
	  strcat(sub,subsub);
	  count=1;
	  now=str[j]-'0';
	}else count++;
	if(j==strlen(str)-1){
	  sprintf(subsub,"%d%d",count,now);
	  strcat(sub,subsub);
	}
      }
      strcpy(str,sub);
    }
    puts(str);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    int sum=0,n,m,A[10000];
    cin>>n>>m;
    REP(i,m){
        cin>>A[i];
        sum+=A[i];
    }
    if(n-sum<0)cout<<-1<<endl;
    else cout<<n-sum<<endl;

}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;

int main() {
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
     cin>>a[i];
  }
  map<int,int>k;
  for(int i=0;i<N;i++){
     if(a[i]>=1&&a[i]<=399){k[1]++;}
     if(a[i]>=400&&a[i]<=799){k[2]++;}
     if(a[i]>=800&&a[i]<=1199){k[3]++;}
     if(a[i]>=1200&&a[i]<=1599){k[4]++;}
     if(a[i]>=1600&&a[i]<=1999){k[5]++;}
     if(a[i]>=2000&&a[i]<=2399){k[6]++;}
     if(a[i]>=2400&&a[i]<=2799){k[7]++;}
     if(a[i]>=2800&&a[i]<=3199){k[8]++;}
     if(a[i]>=3200){k[9]++;}
  }
  int count=0;int count2=0;
  for(auto a:k){
   if(a.first<=8&&a.second>=1){count++;}
   if(a.first==9&&a.second>=1){count2=a.second;}
  }
  if(count>0){cout<<count<<" "<<count+count2<<endl;}
  else {cout<<1<<" "<<count2<<endl;}
return 0;}

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

int main(){
	int N;
	cin >> N;
	map<pair<int,int>,int> memo;
	for(int i = 0 ; i < N ; i++){
		int x,y,w;
		cin >> x >> y >> w;
		memo[{x-1,y-1}] += w;
		memo[{x,y}] += w;
		memo[{x-1,y}] += w;
		memo[{x,y-1}] += w;
	}
	int ans = 0;
	for( auto i : memo )
		ans = max(ans,i.second);
	cout << ans << " / " << 1 << endl;
		
		
}

Measured memory_bytes: 28084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int cnt = 0;
    rep(i, s.size()){
        if(s[i]=='1') cnt++;
    }
    int cntz = s.size()-cnt;
    
    cout << min(cnt, cntz)*2 << endl;
}

Measured memory_bytes: 512
<?php
   fscanf(STDIN, "%d", $n);
     $ans=1;
   $arr = array_map('intval', explode(' ', trim(fgets(STDIN))));
   if (in_array('0', $arr)){
     $ans= 0;
   }else{
     for($i=0;$i<$n;++$i){
      $ans=bcmul($ans,$arr[$i]);
      if($ans>1000000000000000000){
        $ans= -1;
        break;
       }
     }
    }
   echo $ans;


Measured memory_bytes: 28860
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>

struct Coordinate {
	int x, y;
};
int main() {
	std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
	int height, width, kick; std::cin >> height >> width >> kick;
	Coordinate start, goal; std::cin >> start.x >> start.y >> goal.x >> goal.y; --start.x; --start.y; --goal.x; --goal.y;
	std::vector<std::string> state(height); for (auto& line : state) std::cin >> line;
	std::vector<std::vector<int>> horizontal(height, std::vector<int>(width, INT_MAX)), vertical(height, std::vector<int>(width, INT_MAX));
	std::vector<std::set<int>> h_leaf(height), v_leaf(width);
	for (auto i = 0; i < height; ++i) {
		for (auto j = 0; j < width; ++j) {
			if (state[i][j] == '@') {
				h_leaf[i].insert(j);
				v_leaf[j].insert(i);
			}
		}
	}
	for (auto i = 0; i < height; ++i) {
		h_leaf[i].insert(-1); h_leaf[i].insert(width);
	}
	for (auto i = 0; i < width; ++i) {
		v_leaf[i].insert(-1); v_leaf[i].insert(height);
	}
	std::queue<Coordinate> queue;
	horizontal[start.x][start.y] = 0;
	vertical[start.x][start.y] = 0;
	queue.push(start);
	while (!queue.empty()) {
		const auto top = queue.front(); queue.pop();
		const auto count = std::min(horizontal[top.x][top.y], vertical[top.x][top.y]) + 1;
		horizontal[top.x][top.y] = std::min(horizontal[top.x][top.y], count);
		vertical[top.x][top.y] = std::min(vertical[top.x][top.y], count);
		for (auto nx = std::min(top.x + kick + 1, *v_leaf[top.y].lower_bound(top.x)) - 1; top.x < nx; --nx) {
			if (horizontal[nx][top.y] <= count) break;
			horizontal[nx][top.y] = count;
			queue.push(Coordinate{ nx, top.y });
		}
		for (auto nx = std::max(top.x - kick - 1, *std::prev(v_leaf[top.y].lower_bound(top.x))) + 1; nx < top.x; ++nx) {
			if (horizontal[nx][top.y] <= count) break;
				horizontal[nx][top.y] = count;
				queue.push(Coordinate{ nx, top.y });
		}
		for (auto ny = std::min(top.y + kick + 1, *h_leaf[top.x].lower_bound(top.y)) - 1; top.y < ny; --ny) {
			if (vertical[top.x][ny] <= count) break;
			vertical[top.x][ny] = count;
			queue.push(Coordinate{ top.x, ny });
		}
		for (auto ny = std::max(top.y - kick - 1, *std::prev(h_leaf[top.x].lower_bound(top.y))) + 1; ny < top.y; ++ny) {
			if (vertical[top.x][ny] <= count) break;
			vertical[top.x][ny] = count;
			queue.push(Coordinate{ top.x, ny });
		}
	}
	const auto result = std::min(horizontal[goal.x][goal.y], vertical[goal.x][goal.y]);
	if (result != INT_MAX) {
		std::cout << result << '\n';
	}
	else {
		std::cout << "-1\n";
	}
}

Measured memory_bytes: 153556
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll dp[200][200000];

int main() {
  int n,w;
  cin >> n >> w;
  vl W(n),V(n);
  rep(i,n)cin >> W[i] >> V[i];

  rep(i,n){
    rep(j,w+1){
      maxs(dp[i+1][j],dp[i][j]);
      if((j-W[i]) <0)continue;
      maxs(dp[i+1][j],dp[i][j-W[i]] + V[i]);
    }
  }
  cout<<dp[n][w]<<endl;
  return 0;
}

Measured memory_bytes: 156416
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const ll mod = 1000000007;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    map<ll, int> za;
    rep(i,n){
        cin >> a[i];
        if(za.find(a[i]) == za.end()){
            za[a[i]] = i;
        }
        else{
            cout << 0 << endl;
            return 0;
        }
    }
    vector<ll> b(m);
    map<ll, int> zb;
    rep(i,m){
        cin >> b[i];
        if(zb.find(b[i]) == zb.end()){
            zb[b[i]] = i;
        }   
        else{
            cout << 0 << endl;
            return 0;
        }
    }
    vector<int> useda(n, false), usedb(m, false);
    int cnta = 0, cntb = 0;
    int alla = 0, allb = 0;
    ll ans = 1;
    ll rest = 0;
    for(int i = n*m; i > 0; --i){
        bool fa = (za.find(i) != za.end());
        bool fb = (zb.find(i) != zb.end());
        if(fa && fb){
            if(useda[za[i]] || usedb[zb[i]]){
                cout << 0 << endl;
                return 0;
            }
            useda[za[i]] = true;
            usedb[zb[i]] = true;
            rest += cnta++ + cntb++;
            ++alla;
            ++allb;
        }
        else if(fa){
            if(useda[za[i]] || cnta == 0){
                cout << 0 << endl;
                return 0;
            }
            (ans *= cnta) %= mod;
            rest += cnta - 1;
            useda[za[i]] = true;
            ++alla;
            ++cntb;
        }
        else if(fb){
            if(usedb[zb[i]] || cntb == 0){
                cout << 0 << endl;
                return 0;
            }
            (ans *= cntb) %= mod;
            rest += cntb - 1;
            usedb[zb[i]] = true;
            ++allb;
            ++cnta;
        }
        else{
            if(rest == 0){
                cout << 0 << endl;
                return 0;
            }
            (ans *= rest) %= mod;
            --rest;
        }
    }
    cout << ans << endl;
    return 0;
}


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


int main()
{
    BeatMeScanf;
    ll x;
    cin>>x;
    ll ans=0;
    ans=(x/500)*1000;
    ans+=((x%500)/5)*5;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
L = gets.split.map(&:to_i).sort
ans = 0
1.upto(N-1) do |l2|
    (l2+1).upto(N-1) do |l1|
        len1 = L[l1]
        len2 = L[l2]
        a = L.bsearch_index{|l| l > len1 - len2}
        ans += l2 - a if !a.nil? && l2 - a > 0
    end
end
p ans

Measured memory_bytes: 1912
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y, h;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++)
		sum *= (x--);
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, a, b, in, out;
string s;
signed main() {
	cin >> n >> a >> b >> s;
	for (int i = 0; i < n; i++) {
		bool l = 0;
		if (s[i] == 'a') {
			if (in + out < a + b) {
				l = 1;
				in++;
			}
		}
		else if (s[i] == 'b') {
			if (in + out < a + b&&out < b) {
				l = 1;
				out++;
			}
		}
		if (l) cout << "Yes\n";
		else cout << "No\n";
	}
	getchar(); getchar();
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    string S;
    bool d = true;
    cin >> a >> b >> S;
    for(int i = 0; i < S.size();i++){
        if(i != a)
        {
            if(S[i] < '0' || S[i] > '9'){
            d = false;
            break;}
        }
        if(i == a)
        {
            if(S[i] != '-'){
            d = false;
            break;}
        }
    }
    if(d) cout << "Yes" << endl;
    if(!(d)) cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define N 100010
int d[N],in[N],ans[N];
vector<int> mp[N];
int main(){
    int m,n,a,b;
    int h1,m1,h2,m2,k;
    char t[200010];
    while (scanf("%s",t)!=EOF) {
        for (int i=0;i<strlen(t);i++) {
            if (t[i]!='?')
                printf("%c",t[i]);
            else
                printf("D");
        }
        printf("\n");
    }
    return 0;
}




Measured memory_bytes: 5708
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  vector <int> S(N);
  for(int i = 0; i < N; i++) {
      S.at(i) = i+1;
  }
  
  int d;
  int a;
  vector<vector<int>> A(K);
  for(int i = 0; i < K; i++) {
      cin >> d;
      for(int j = 0; j < d; j++) {
          cin >> a;
          A.at(i).push_back(a);
      }
  }
  
  for(int i = 0; i < K; i++) {
      for(int j = 0; j < A.at(i).size(); j++) {
          for(int k = 0; k < N; k++) {
              if(S.at(k) == A.at(i).at(j)) {
                  S.at(k) = 0;
              }
          }
      }
  }
  
  int cnt = 0;
  for(int i = 0; i < N; i++) {
      if(S.at(i) != 0) {
          cnt++;
      }
  }
  cout << cnt <<endl;
}

Measured memory_bytes: 3628
#include <vector>
#include <cassert>
#include <iostream>
using namespace std;
const int mod = 1000000007;

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

	vector<vector<int>> dp(H + 1, vector<int> (W, 0)); 

    dp[0][0] = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			for (int k = 0; k < 1 << (W - 1); k++) {
				// 2 つの横線がつながっていないか調べる
				bool ok = true;
				for (int l = 0; l < W - 2; l++) {
					if (((k >> l) & 1) && ((k >> (l + 1)) & 1)) {
						ok = false;
					}
				}

				if (ok) {
					if (j >= 1 && ((k >> (j - 1)) & 1)) {
						// 左方向に横線をたどるケース
						dp[i + 1][j - 1] += dp[i][j];
						dp[i + 1][j - 1] %= mod;
					}
					else if (j <= W - 2 && ((k >> j) & 1)) {
						// 右方向に横線をたどるケース
						dp[i + 1][j + 1] += dp[i][j];
						dp[i + 1][j + 1] %= mod;
					}
					else {
						// 横線をたどらないケース
						dp[i + 1][j] += dp[i][j];
						dp[i + 1][j] %= mod;
					}
				}
			}
		}
	}

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

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

using namespace std;

map < pair < int, int >, int > cnt;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, cur = 1;
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        if (n % 2 == 1) cout << i << " " << n - i + 1 << '\n';
        else {
            if (i < n / 2 - i + 1) cout << i << " " << n / 2 - i + 1 << '\n';
            else {
                cout << n / 2 + cur << " " << n - cur << '\n';
                cur++;
            }
        }
    }
    /*for (auto key : cnt) {
        if (key.second == 2) {
            cout << key.first.first << " " << key.first.second << " " << key.second << endl;
            return 0;
        }
    }*/
    return 0;
}



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

int main() {
	int k,n,max=0;
	cin>>k>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	for(int i=0;i<n-1;i++){
		b[i]=a[i+1]-a[i];
	}
	b[n-1]=(k-a[n-1])+a[0];
	
	for(int i=0;i<n;i++){
		if(max<=b[i])max=b[i];
	}
	
	cout<<k-max<<endl;
}



Measured memory_bytes: 1920