akhauriyash/Code-Regression huggingface dataset:
// Problem : B - A to Z String
// Contest : AtCoder - AtCoder Beginner Contest 053
// URL : https://atcoder.jp/contests/abc053/tasks/abc053_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'

using namespace std;


int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	int l = -1, r, n = s.size();
	for(int i = 0; i < n; i++){
	    if(s[i]=='A'&&l==-1){
	        l = i;
	    }
	    if(s[i]=='Z') r = i;
	}
	cout << r-l+1;
	return 0;
}

Measured memory_bytes: 720
N = int(input())
A = list(map(int,input().split()))

flg = True
cnt = 0
i = 0
while flg:
    flg = False
    #末尾(N-1)から先頭(i)に向けてソートする
    for j in range(N-1,i,-1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1],A[j]
            cnt += 1
            flg = True
    #一番小さい数字が確定するごとにiをカウントアップ
    i += 1
print(*A)
print(cnt)



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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  int reverseCount = 0;
  rep(i, q) {
    int t;
    cin >> t;
//    scanf("%d", &t);
    if (t == 1) {
      reverseCount++;
    } else {
      int f;
//      char c[1];
      string ss;
      cin >> f;
      cin >> ss;
//      scanf("%d ", &f);
//      scanf("%s", c);
//      string ss(1, c[0]);
      bool reversed = reverseCount % 2 == 1;
      if ((f == 1 && !reversed) || (f != 1 && reversed)) {
        s.insert(0, ss);
      } else {
        s.append(ss);
      }
    }
  }
  if (reverseCount % 2 == 1) {
    reverse(s.begin(), s.end());
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int count = 0;
  for(int i = 0; i < 100; i++){
    for(int j = 0; j < 100; j++){
      if(N == 4*i + 7*j){
        count++;
      }
    }
  }
  string ans;
  if(count != 0){
    ans = "Yes";
  }else{
    ans = "No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define forout(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
int n,h[100005];
int f[100005];
int main()
{
    cin>>n;
    forinc(i,1,n) cin>>h[i];
    f[1]=0;
    f[2]=abs(h[2]-h[1]);
    forinc(i,3,n)
    {
        f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<f[n];

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    string ch="YAKI";
    cin>>s;
    bool flag=0;
    for(int i=0;i<ch.length();i++)
    {
        if(s[i]!=ch[i])
            flag=1;
    }
    if(!flag)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

void bubblesort(int *,int);

void bubblesort(int *A,int N)
{
  int a,i,flag=1,count=0;

  while(flag) {
    flag = 0;
    for(i=N-1;i>=1;i--){
    if(A[i] < A[i-1]) {
      a = A[i];
      A[i] = A[i-1];
      A[i-1] = a;
      flag = 1;
      count++;
    }
   }
  }

  for(i=0;i<N;i++) {
      printf("%d",A[i]);
      if(i<N-1)printf(" ");
  }
    
    printf("\n");
    
    printf("%d\n",count);
}

int main()
{
    int N,A[100],i;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    scanf("%d",&A[i]);
    
    bubblesort(A,N);

    return 0;
}



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

struct data{
  int t, s, d;
};

bool comp(const data &a, const data &b)
{
  return a.t < b.t;
}

int main()
{
  while(1){
    int N, M;
    cin >> N >> M;
    if(N == 0 && M == 0) break;
    vector<data> v(M);
    for(int i = 0; i < M; i++){
      cin >> v[i].t >> v[i].s >> v[i].d;
    }
    sort(v.begin(),v.end(),comp);
    vector<bool> c(N+1);
    fill(c.begin(),c.end(),false);
    c[1] = true;
    for(int i = 0; i < M; i++)
      if(c[v[i].s])
        c[v[i].d] = c[v[i].s];
    cout << count(c.begin(),c.end(),true) << endl;
  }
}

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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 100000000
ll n,cap,w[105],v[105];
ll dp[102][100005];
ll f(ll i, ll cap){

    if(i>=n || cap<=0) return 0;

    if(dp[i][cap]!=-1) return dp[i][cap];

    ll ret1=0,ret2=0;

    if(cap>=w[i]) ret1 = v[i]+f(i+1,cap-w[i]);
    ret2 = f(i+1,cap);


    return dp[i][cap] = max(ret1,ret2);




}


int main(){

    cin>>n>>cap;
    for(ll i=0;i<n;i++) cin>>w[i]>>v[i];
    memset(dp,-1,sizeof(dp));
    cout<<f(0,cap);
    return 0;
}


Measured memory_bytes: 80000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 500005;
const ll MOD = 1000000007;

ll n;
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n;
    ll ans = 0x3f3f3f3f3f3f3f3f;
    for (ll i=1; i*i<=n; i++) {
        if (n%i == 0) {
            ans = min(ans, n/i+i-2);
        }
    }

    cout << ans << endl;

}


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

#define F first
#define S second
#define llong long long
#define ullong unsigned long long
#define mp make_pair
#define pb push_back
#define sz(v) (int)v.size()

using namespace std;

const int MXN = (int)1e6 + 10;
const int INF = (int)1e9 + 7;
const llong LINF = (llong)1e18 + 10;
const double EPS = (double)1e-9;
const double PI = (double)acos(-1.0);

int n;
int a[100001][2];
int pref[100001][2];

int main(){
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif 
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i][0]);
	}
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i][1]);
	}
	for(int i = 1; i <= n; ++i){
	  pref[i][0] = pref[i - 1][0] + a[i][0];
		pref[i][1] = pref[i - 1][1] + a[i][1];
	}
	int ans = 0;
	for(int i = 1; i <= n; ++i){
		ans = max(ans, pref[i][0] + pref[n][1] - pref[i - 1][1]);
	}
	printf("%d", ans);
  return 0;
}


Measured memory_bytes: 256
x,y,a,b,c = map(int,input().split())
p_ = list(map(int,input().split()))
q_ = list(map(int,input().split()))
r_ = list(map(int,input().split()))
p_.sort(reverse=True)
q_.sort(reverse=True)
r_.sort(reverse=True)
red = x-1
gre = y-1
mu = 0
while True:
    if mu == c:
        break
    else:
        if red >= 0:
            badr = p_[red]
        else:
            badr = 1000000000
        if gre >= 0:
            badg = q_[gre]
        else:
            badg = 1000000000
        badmu = r_[mu]
        if badr <= badg:
            if badr < badmu:
                red = red-1
                mu = mu+1
            else:
                break
        else:
            if badg < badmu:
                gre = gre-1
                mu = mu+1
            else:
                break
ans = 0
for i in range(red+1):
    ans += p_[i]
for i in range(gre+1):
    ans += q_[i]
for i in range(mu):
    ans += r_[i]
print(ans)

Measured memory_bytes: 23216
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  MAX = 10**9 + 7
  counts = [0] * 26
  
  n = int(input())
  dp = [[0]*2 for _ in range(26)] 
  for c in list(input().strip()):
    counts[ord(c) - 97] += 1
    
  dp[0][0] = 1
  dp[0][1] = counts[0]
  for i, count in enumerate(counts[1:], 1):
    if count == 0:
      dp[i] = dp[i-1]
      continue
    dp[i][0] = sum(dp[i-1]) % MAX
    dp[i][1] = (dp[i][0] * counts[i]) % MAX
  
  print((sum(dp[-1]) - 1) % MAX)

if __name__=='__main__':
  main()



Measured memory_bytes: 3956
/// 1行の文字を空白で分割してVec<T>にする。
fn read_split<T : std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

fn main() {
    let input : Vec<i32> = read_split();
    let answer = if input[2] < input[0] {0} else {input[2] / input[0] * input[1]};
    println!("{}", answer);
}

Measured memory_bytes: 4352
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    ai, bi = 0, 0
    al, bl = [], []
    while ai < n and bi < n:
        ax, bx = a[ai], b[bi]
        la, lb = [], []
        if ax == bx:
            cnt = 2

            la.append(ai)
            ai += 1
            while ai < n and a[ai] == ax:
                la.append(ai)
                cnt += 1
                ai += 1

            lb.append(bi)
            bi += 1
            while bi < n and b[bi] == bx:
                lb.append(bi)
                cnt += 1
                bi += 1

            if cnt > n:
                print('No')
                exit()

        elif ax < bx:
            la.append(ai)
            ai += 1
        else:
            lb.append(bi)
            bi += 1

        al.append(la)
        bl.append(lb)

    print('Yes')

    slit = 0
    for i in range(len(al)):
        if len(al[i]) == 0 or len(bl[i]) == 0:
            continue
        if al[i][-1] - bl[i][0] + 1 > slit:
            slit = al[i][-1] - bl[i][0] + 1

    print(' '.join(map(str, b[n-slit:] + b[:n-slit])))

main()

Measured memory_bytes: 164952
#include <stdio.h>
int main(void)
{
   int i,a=0, b=0, c=0;
   char s[3];

   scanf("%s",s);

   for(i=0;i<3;i++){
      if(s[i]=='a')
         a++;
      else if(s[i]=='b')
         b++;
      else 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
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cassert>
#define SIZE 100005

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

ll A[SIZE];
ll B[SIZE];
bool use[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld %lld",&A[i],&B[i]);
	ll sa=0,sb=0;
	for(int i=0;i<n;i++) sa+=A[i],sb+=B[i];
	vector <P> vx;
	for(int i=0;i<n;i++)
	{
		vx.push_back(P(A[i],i));
		vx.push_back(P(B[i],i));
	}
	sort(vx.begin(),vx.end());
	for(int i=0;i<n;i++) use[vx[i].second]=true;
	bool up=true;
	for(int i=0;i<n;i++)
	{
		if(!use[i])
		{
			up=false;
		}
	}
	ll ret=0;
	if(!up)
	{
		for(int i=0;i<n;i++) ret+=vx[i].first;
	}
	else
	{
		for(int i=0;i<n;i++) ret+=vx[i].first;
		ll mn=-1;
		for(int i=0;i<n;i++)
		{
			ll vl;
			if(i==vx[n-1].second)
			{
				vl=max(A[i],B[i])-vx[n-2].first;
			}
			else
			{
				vl=max(A[i],B[i])-vx[n-1].first;
			}
			if(mn==-1) mn=vl;
			else mn=min(mn,vl);
		}
		ret+=mn;
	}
	ret=min(ret,sa);
	ret=min(ret,sb);
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 3956
def warshall_floyd(d, V, M): #d[i][j]は2頂点間i, j間の移動コストを格納, Vは頂点数
    for k in range(V):
        for i in range(V):
            for j in range(V):
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])
                
    return d
    
N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
dist = [[10 ** 5 for i in range(N)] for i in range(N)]

for l in L:
    l[0] -= 1
    l[1] -= 1
      
for i in range(M):
    dist[L[i][0]][L[i][1]] = L[i][2]
    dist[L[i][1]][L[i][0]] = L[i][2]

dist = warshall_floyd(dist, N, M)

res = 0

for i in range(M):
    if dist[L[i][0]][L[i][1]] != L[i][2]:
        res += 1
            
print(res)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

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

int pow(int a,int b){
	if(b == 0)return 1;
	int res = pow(a,b/2);
	res = res*res;
	if(b&1)res *= a;
	return res;
}



int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){

     
 // }

     int n,m;
     cin >> n >> m;
     int arr[m];
     fo(i,0,m)cin >> arr[i];
int total = 0;
fo(i,0,m)total += arr[i];
// cout << total << endl;
int p = -1;
if(n-total >= 0)cout << n-total << endl;
else cout << -1 << endl;




return 0;
	
	}




Measured memory_bytes: 3724
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */
int main()
{
	int		i=0,j,x[10001],y[10001];

	
	do {
		i++;
		scanf("%d %d", &x[i],&y[i]);
	} while((x[i]!=0)||(y[i]!=0));

	for(j=1;j<i;j++) {
		printf("%d %d\n",min(x[j],y[j]), max(x[j],y[j]));
	}
	
	return 0;
}



Measured memory_bytes: 2052
import bisect

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

L.sort()

ans = 0
for i in range(N-2):
    for j in range(N-i-1):
        a = L[i]
        b = L[i+j+1]
        c_right = bisect.bisect_left(L, b + a, i+j+2)
        ans += c_right - (i+j+2)
print(ans)


Measured memory_bytes: 45988
def main():
    S = input()
    K = int(input())
    ans = ''
    for s in S:
        if 123 - ord(s) <= K and s != 'a':
            ans += 'a'
            K -= 123-ord(s)
        else:
            ans += s
    if K > 0:
        ans = ans[:-1] + chr((ord(ans[-1])+K-97) % 26+97)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
#include<iostream>
using namespace std;
int main() {
  string s;
  int k;
  cin >> k >> s;
  
  if (s.size() <= k) {
    cout << s << endl;
  }
  else  {
    for (int i = 0; i < k; i++) {
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define pri 1000000007
#define all(x) x.begin(),x.end()
#define mnx 1000001
#define pr pair<ll,ll>
using namespace std;

void masterstroke(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll gc=__gcd(c,d);
ll l=(c*d)/gc;
ll x1=(b/c)-((a-1ll)/c);
ll y1=(b/(d))-((a-1ll)/d);
ll z1=(b/l)-((a-1ll)/l);
cout<<((b-a+1ll)-(x1+y1-z1))<<endl;	
}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)masterstroke();
}


Measured memory_bytes: 256
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
const int maxs = 103;
const int MAXS = 500;
int a[maxs];
int fact[maxs];
int dp[maxs][maxs][MAXS];
int n,k;


void pre()
{
    fact[0] = fact[1] = 1;
    
    for(int i = 2;i < maxs;++i)
        fact[i] = (i * fact[i - 1]) % mod;
}

int go(int pos,int start,int XOR)
{
    if(pos == n + 1)
    {
        if(XOR == k && start == 0)
            return 1LL;
        else
            return 0LL;
    }
    if(start == 0)
    {
        if(XOR == k)
            return 1LL;
        else
            return 0LL;
    }
    
    if(dp[pos][start][XOR] != -1)
        return dp[pos][start][XOR];
    
    int ans = 0;
    
    ans = (ans % mod + go(pos + 1,start - 1,XOR ^ a[pos]) % mod) % mod;
    ans = (ans % mod + go(pos + 1,start,XOR) % mod) % mod;
    
    return dp[pos][start][XOR] = ans;
}


signed main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    pre();
    
    memset(dp,-1,sizeof dp);
    
    cin >> n >> k;
    
    for(int i = 1;i <= n;++i)
        cin >> a[i];
    
    int ans = 0;
        
   for(int i = 1;i <= n;++i)
   {
       int res = (go(1,i,0) % mod * fact[i] % mod) % mod;
       ans = (ans % mod + res % mod) % mod;
   }
   
   cout << ans << '\n';
}


Measured memory_bytes: 45108
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100010];
bool vis[100010];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	long long res=0;
	for(int i=1;i<=n;i++){
		res+=a[i]/2;
		if(a[i]!=0)
			vis[i]=true;
		a[i]%=2;
	}
	for(int i=1;i<=n;i++){
		if(a[i]&&a[i+1]){
			res++;
			a[i]=0;
			a[i+1]=0;
		}
		if(a[i-1]&&vis[i]){
			a[i-1]=0;
			a[i]=1;
		}
		if(a[i]&&a[i+1]){
			res++;
			a[i]=0;
			a[i+1]=0;
		}
	}
	cout<<res<<endl;
	return 0;
}


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

int n;
vector<int> G[100010];

int d[2][100010];
void dist(int s,int* ret){
	for(int i=1;i<=n;i++)ret[i]=-1;
	queue<int> que;
	ret[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front(); que.pop();
		for(int u: G[v]){
			if(ret[u]==-1){
				ret[u]=ret[v]+1;
				que.push(u);
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	dist(1,d[0]);
	dist(n,d[1]);
	int s=1,t=n;
	while(1){
		for(int u: G[s]){
			if(d[1][u]<d[1][s]){
				s=u;
				break;
			}
		}
		if(s==t){
			for(int u: G[s]){
				if(d[0][u]<d[0][s]){
					s=u;
					break;
				}
			}
			break;
		}
		for(int u: G[t]){
			if(d[0][u]<d[0][t]){
				t=u;
				break;
			}
		}
		if(s==t){
			for(int u: G[t]){
				if(d[1][u]<d[1][t]){
					t=u;
					break;
				}
			}
			break;
		}
	}
	dist(s,d[0]);
	dist(t,d[1]);
	s=t=0;
	for(int i=1;i<=n;i++){
		if(d[0][i]<d[1][i])s++;
		else t++;
	}
	if(s>t)puts("Fennec");
	else puts("Snuke");
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
#define int long long 

int dist[401010];

signed main(void){
  
  int N,x,y; cin >> N >> x >> y;
  
  for(int i = 1; i < N; i++){ 
    for(int j = i+1; j <= N; j++){ 
      
      int k = min(j-i,abs(x-i)+1+abs(j-y));
      
      dist[k]++;
      
    }
  }
  
  for(int k = 1; k < N; k++){ 
    
    cout << dist[k] << endl;
    
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n;
    cin>>n;
    long long int sum=0;
    if (n%2==0) {
        for (long long int i=10;i<=n;i*=5) {
            sum+=n/i;
        }
        cout<<sum<<endl;
    } else {
        cout<<0<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nn "\n"


int main() {

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	ios::sync_with_stdio(0);
	cin.tie(0);

	int n, w; cin >> n >> w;

	std::vector<ll> val(n), wt(n);

	for (int i = 0; i < n; ++i) cin >> wt[i] >> val[i];

	vector<vector<ll> > dp(n + 1, vector<ll> (w + 1, 0));



	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= w; ++j) {
			if (wt[i - 1] > j) {
				dp[i][j] = dp[i - 1][j];
			} else {
				dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - wt[i - 1]]);
			}
		}
	}

	cout << dp[n][w];
	return 0;
}


Measured memory_bytes: 80256
#include "bits/stdc++.h"
using namespace std;

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(40) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,n,a) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef pair<long long, long long> pll;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e9)
#pragma endregion

int main() {
	int n, k; put n >> k;
	n -= 2;
	int sum = ( n / 11 ) * 5;
	n = n % 11;
	int table[5][12];
	table[0][0] = 4;
	if (n == 0) goto END;
	rep(i, 4) {
		table[i+1][0] = (table[i][0] + 9) % 11;
		if (table[i+1][0] == k) sum++;
	}
	rep(j ,5) {
		REP(i,1, n) {
			table[j][i] = (table[j][i-1] + 63 ) % 11;
			if (table[j][i] == k)sum++;
		}
	}
END:
	putans(sum);
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String input = br.readLine();
			if(input.equals("0 0")){
				break;
			}
			String[] numbers = input.split(" ");
			Integer max = Integer.parseInt(numbers[0]);
			Integer target = Integer.parseInt(numbers[1]);
			ArrayList<Integer[]> result = new ArrayList<Integer[]>();
			String result_size = "";
			for(int i = 1; i <= max; i++){
				for(int j = 1; j <= max; j++){
					if(j != i){
						for(int k = 1; k <= max; k++){
							if(k != i && k != j){
								if(i + j + k == target){
									Integer[] comb = {i, j, k};
									Arrays.sort(comb);
									boolean is_contain = false;
									for(int l = 0; l< result.size(); l++){
										if(result.size() > 0 && Arrays.equals(result.get(l), comb)){
											is_contain = true;
										}
									}
									if(!is_contain){
										result.add(comb);
									}
								}
							}
						}
					}
				}
			}
			result_size = result_size + result.size() + "\n" ;
			System.out.print(result_size);
		}
	}
}

Measured memory_bytes: 31596
#include <bits/stdc++.h>
#define xx first
#define yy second
#define D if(0)
#define cerr D cerr

using namespace std;
typedef long long ll;

template <typename T>
vector<T> read_n(ll n) {
  vector<T> ret(n);
  for(ll i = 0; i < n; i++) cin >> ret[i];
  return ret;
}

template <typename iter>
void dump(iter begin, iter end) {
  for(iter it = begin; it != end; it++) {
    if(it != begin) cout << " ";
    cout << *it;
  } cout << endl;
}

const ll top = 1e18;

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

  ll a; cin >> a;

  string b; cin >> b;
  assert(b[b.size() - 3] == '.');
  b[b.size() - 3] = ' ';

  istringstream iss(b);

  ll B = 0;
  ll u, v; iss >> u >> v;
  B = u * 100 + v;

  cout << (a * B) / 100 << "\n";

  return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N,Q;
const int MAX_N = 100100;
bool dp[MAX_N][2];
int main() {
  cin >> N >> Q;
  dp[0][0] = true;
  for (int i = 0; i < Q; i++){
    int a,b;
    cin >> a >> b;
    a--,b--;
    if (dp[a][0]){
      if (a - 1 >= 0){
        dp[a - 1][1] = true;
      }
      if (a + 1 < N){
        dp[a + 1][1] = true;
      }
    }
    if (dp[b][0]){
      if (b - 1 >= 0){
        dp[b - 1][1] = true;
      }
      if (b + 1 < N){
        dp[b + 1][1] = true;
      }
    }

    bool a0,b0;
    a0 = b0 = false;
    bool a1,b1;
    a1 = b1 = false;
    if (dp[a][0]){
      b0 |= true;
    }
    if (dp[a][1]){
      b1 |= true;
    }
    if (dp[b][0]){
      a0 |= true;
    }
    if (dp[b][1]){
      a1 |= true;
    }
    if (a - 1 >= 0 and dp[a - 1][0]){
      b1 |= true;
    }
    if (a + 1 < N and dp[a + 1][0]){
      b1 |= true;
    }
    if (b - 1 >= 0 and dp[b - 1][0]){
      a1 |= true;
    }
    if (b + 1 < N and dp[b + 1][0]){
      a1 |= true;
    }
    dp[a][0] = a0;
    dp[a][1] = a1;
    dp[b][0] = b0;
    dp[b][1] = b1;

  }

  int cnt = 0;
  for (int i = 0; i < N; i++){
    if (i - 1 >= 0){
      dp[i - 1][1] |= dp[i][0];
    }
    if (i + 1 < N){
      dp[i + 1][1] |= dp[i][0];
    }
  }
  for (int i = 0; i < N; i++){
    cnt += (dp[i][0] | dp[i][1]);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 512
/**akshaykumar99**/

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

#define f(i,x,n) for(i=x;i<n;i++)
#define pu push_back           
#define pp pop_back
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int MOD=1e9+7 ;
const long long INF=1e15;
const long long LINF=LLONG_MAX;

typedef long long ll;
typedef long double ld;
typedef vector<ll> lvc;
typedef pair<ll,ll> lpr;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
 
  ll a,b,i;
  cin>>a>>b;
  for(i=b-a+1;i<a+b;i++)
    cout<<i<<" ";

    


}

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

using namespace std;

void solve() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for (int i = 0; i < H; i++)
    {
        cin >> a[i];
    }
    
    vector<bool> row(H, false), col(W, false);
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (a[i][j] == '#')
            {
                row[i] = true;
                col[j] = true;
            }
        }
    }
    
    for (int i = 0; i < H; i++)
    {
        if (row[i])
        {
            for (int j = 0; j < W; j++)
            {
                if (col[j])
                {
                    cout << a[i][j];
                }
                
            }
            cout << endl;
        }
    }
}

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

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

int a[505][505];

int main() {
	int n, m;
	int h, w;
	scanf("%d%d%d%d", &n, &m, &h, &w);
	ll sum = 0;
	int k = (1e9-1) / (w*h-1);
	for (int i=0 ; i<n ; i++) {
		for (int j=0 ; j<m ; j++) {
			if ((i+1)%h == 0 and (j+1)%w == 0) a[i][j] = -k*(w*h-1)-1;
			else a[i][j] = k;
			sum += a[i][j];
		}
	}
	if (sum > 0) {
		printf("Yes\n");
		for (int i=0 ; i<n ; i++) {
			for (int j=0 ; j<m ; j++) {
				printf("%d ", a[i][j]);
			}
			printf("\n");
		}
	} else printf("No\n");
	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main() {
std::cout << std::fixed;
  std::cout << std::setprecision(9);
int n;
cin >> n;double arr[n];
for(int i = 0; i < n; i++)cin >> arr[i];
double dp[n+5][n+5] = {0};
dp[0][1] = 1;
for(int i = 1; i <= n; i++)
for(int j = 1; j < i+2; j++){
dp[i][j] += dp[i-1][j-1]*arr[i-1] + dp[i-1][j]*(1-arr[i-1]);
}
double ans = 0;
for(int i = (int)(n+1)/2 + 1; i <= n + 1;i++)ans += dp[n][i];
cout << ans;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  string S, T;
  cin >> S >> T;
  if(S == T.substr(0,S.size())){
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

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

int main() {
  string s;
  cin >> s;
  ll n = stoll(s);
  
  int digit = 0;
  ll n1 = n;
  while (n1 > 0) {
    n1 /= 10;
    ++digit;
  }
  
  ll ans = 999;
  REP(i, digit - 2) {
    ll tmp = n;
    REP(j, i) {
      tmp /= 10;
    }
    tmp %= 1000;
    ans = min(ans, abs(753 - tmp));
  }
  
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;

struct vw_pair {
    int v, w;
    vw_pair(int v,int w) : v(v), w(w) {};
};

typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<int> vi;
typedef vector <string> vs;
typedef vector <vi> vvi;
typedef vector <vector<vw_pair>> adj_list;
typedef vector <bool> vb;
typedef long long ll;
typedef unsigned long long ull;
typedef priority_queue<int> max_heap_int;
typedef priority_queue<int, vi, greater<>> min_heap_int;

#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)

#define modulo(S, N) ((S) & (N-1))   // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S-1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
#define turnOffLastConsecutiveBits(S) ((S) & (S+1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S-1))
#define in_range(lo, hi, x) ((x >= lo && x <= hi))

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

    string s;
    cin >> s;
    int n = s.size(), mmod = 1e9 + 7;
    vvi dp(n, vi(13, 0));
    for (int i=0;i<n;++i) {
        if (s[i] == '?') {
            if (i == 0) {
                for (int num=0;num<10;++num) dp[0][num%13] = 1;
            } else {
                for (int num=0;num<10;++num) {
                    for (int rem=0;rem<13;++rem) {
                        int new_rem = ( (rem * 10) % 13 + num ) % 13;
                        dp[i][new_rem] = (dp[i][new_rem] + dp[i-1][rem]) % mmod;
                    }
                }
            }
        } else {
            int num = s[i] - '0';
            if (i == 0) {
                dp[0][num] = 1;
            } else {
                for (int rem = 0;rem < 13;++rem) {
                    int new_rem = ( (rem * 10) % 13 + num ) % 13;
                    dp[i][new_rem] = dp[i-1][rem];
                }
            }
        }
    }

    cout << dp[n-1][5] << "\n";

    return 0;
}

Measured memory_bytes: 8912
import sys
input = sys.stdin.readline
N = int(input())
s = set()
res = 0

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1] * (n + 1)
    self.rnk = [0] * (n + 1)

  def Find_Root(self, x):
    if self.root[x] < 0:
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if x == y:
      return 
    elif self.rnk[x] > self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x] == self.rnk[y]:
        self.rnk[y] += 1

  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  def Count(self, x):
    return -self.root[self.Find_Root(x)]

uf = UnionFind(2 * 10 ** 5)

for _ in range(N):
  u, v = map(int, input().split())
  s.add(u)
  uf.Unite(u, v + 10 ** 5)

ss = set()
c = [0] * (2 * 10 ** 5 + 1)
for x in s:
  y = uf.Find_Root(x)
  ss.add(y)
  c[y] += 1
for x in ss:
  t = uf.Count(x)
  xc = c[x]
  yc = t - xc
  res += xc * yc
print(res - N)

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

int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int a[27];
  for (int i = 0; i < 27; i ++) a[i] = 0;
  for (int i = 0; i < n; i ++) {
    char t; cin >> t;
    a[t - 'a'] ++;
  }

  long long ans = 1;
  for (int i = 0; i < 27; i ++) {
    ans *= (a[i] + 1);
    ans %= mod;
  }

  cout << ans - 1 << endl;
}

Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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")
    };
}

// ここまで

use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        m: usize,
        q: usize,
        e: [(usize1, usize1); m],
        p: [(usize1, usize1); q],
    }
    let mut cnt = vec![vec![0; n]; n];
    for (l, r) in e {
        cnt[l][r] += 1;
    }
    for r in 1..n {
        for l in (0..r).rev() {
            cnt[l][r] += cnt[l + 1][r] + cnt[l][r - 1] - cnt[l + 1][r - 1];
        }
    }
    for (l, r) in p {
        writeln!(out, "{}", cnt[l][r]).unwrap();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 14456
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    @SuppressWarnings("deprecation")
	public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();
    	int M = sc.nextInt();

    	System.out.println(N*(N-1)/2+M*(M-1)/2);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    ll A,B,K;
    cin>>A>>B>>K;
    if(K>A){
        
        K-=A;
        A=0;
    }
    else{
        A-=K;
        K=0;
    }
    
    if(K>B){
        B=0;
    }
    else{
        B-=K;
    }
        
        cout<<A<<' '<<B<<endl;
    }
    
    



Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin>>N>>M;

    ll a,b;
    vector<vector<ll>> dead(M+1);
    FOR(i,0,N){
        cin>>a>>b;
        if(a<=M){
            dead[a].pb(b);
        }
    }

    priority_queue<ll> q; 

    ll ans=0;

    FOR(i,1,M+1){
        FOR(j,0,dead[i].size()){
            q.push(dead[i][j]);
        }
        if(!q.empty()){
            ans+=q.top();
            q.pop();
        }    
    }

    cout<<ans<<endl;
    
}
//688

Measured memory_bytes: 5632
/**
题目：
链接：
题意：
思路：
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 5000;
int x;
int main()
{
    while(scanf("%d",&x)==1)
    {
        int p = 0, i;
        for(i = 0; 1 ; i++){
            p += i;
            if(p>=x){
                printf("%d\n",i); break;
            }
        }

    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
        #define ll long long
        #define f   first
        #define s   second
        #define pb          push_back
        #define mod        1000000007
        #define mod1       1000000009
        #define hell        998244353
        #define inf         1000000000000000000LL
        #define pi          3.14159265358979323
        #define N           9
        using namespace std;
        ll n,k,sum,q,res,m,val;
        ll x,y;
        void solve()    
        {   
            ll a,b,w;
            cin>>n>>k;
            vector<ll> v(n+1,0);
            for(int i=1;i<=n;i++) cin>>v[i];
            ll cnt=0;
            while(k--)
            {   cnt++;
                vector<ll> pref(n+2,0);
                for(ll i=1;i<=n;i++)
                {
                    ll x=max(i-v[i],1LL);
                    ll y=min(i+v[i],n);
                    pref[x]+=1;
                    pref[y+1]-=1;
                }
                bool f=0;
                for(ll i=1;i<=n;i++)
                    {pref[i]+=pref[i-1];v[i]=pref[i];//cout<<v[i]<<" ";
                        if(pref[i]!=n) f=1;}
                        //cout<<"\n";
                if(!f) break;

            }
            for(int i=1;i<=n;i++) cout<<v[i]<<" ";



        }
        int main()
        {   ios_base::sync_with_stdio(false);
            cin.tie(0);cout.tie(0);
            ll t=1;
            //cin>>t;
            for(int i=1;i<=t;i++)
                solve();
            

        }            

Measured memory_bytes: 6368
# AOJ ITP2_5_B: Sorting Tuples
# Python3 2018.6.24 bal4u

tbl = []
n = int(input())
for i in range(n):
	a = input().split()
	tbl.append((int(a[0]), int(a[1]), a[2], int(a[3]), a[4]))
tbl.sort()
for i in tbl: print(*i)


Measured memory_bytes: 31316
mod = 1000000007
n,k = map(int,input().split())
mp = [1]*(n+1)
dp = [0]*(n+1)
dp[0] =1
for i in range(k):
    mp[int(input())] = 0
dp[1] = dp[0]*mp[0]
for i in range(n-1):
    dp[i+2] = (dp[i+1]*mp[i+1] + dp[i] *mp[i])*mp[i+2]
#     print(dp)
# print(dp)
if n==1 and k == 1:
    print(0)
else:
    print(dp[-1]%mod)







Measured memory_bytes: 460852
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
 
using namespace std;
typedef long long ll;
 
int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
 
 
    ll ans=0;
    ll anss =0;
    ll count=0;
    ll i,j;
  
    ll K;
    vector<ll> a;
 
    ll Q,N;
    string S;
    cin>>N;
    ll flag=0;
    ll t1=0;
    ll t2=0;
 
    for(i=1;i<10;i++){
        if(N%i==0){
            if(N/i<10){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (c-1 <= a+b) {
            System.out.println(b+c);
        } else {
            System.out.println(b*2+a+1);
        }
    }
    
}


Measured memory_bytes: 21844
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    char b;
    scanf("%c", &b);
    switch (b) {
        case 'A':
            printf("T\n"); break;
        case 'C':
            printf("G\n"); break;
        case 'G':
            printf("C\n"); break;
        case 'T':
            printf("A\n"); break;
    }
    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

li = []
for i in range(5):
    li.append(int(input()))
k = int(input())

yay_flag = True
for i, f in enumerate(li):
    for j, g in enumerate(li):
        if abs(li[j] - li[i]) > k:
            print(':(')
            yay_flag = False
            break
    else:
        continue
    break
if yay_flag:
    print('Yay!')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, K;
	string S;
	cin >> N >> S >> K;
	char sk = S[K-1];
	for(int i = 0; i < N; i++){
		if(S[i] != sk)
			S[i] = '*';
	}
	cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define fr(i,n,m) for(ll i=n;i<m;i++)
int main()
{
    ll k;
    scanf("%lli",&k);
    ll c = 7;
    fr(i,0,k)
    {
        c %= k;
        if (c == 0)
        {
            printf("%lli\n",i + 1);
            return 0;
        }
        c = 10*c+7;
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 1732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int a = GetInt();
		int b = GetInt();
		WriteLine($"{a * b} {2 * (a + b)}");
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}


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

ll dp[100][10000];

int main() {
    int m;
    while (cin >> m && m) {
        int a[m], b[m];
        for (int i = 0; i < m; i++) {
            cin >> a[i] >> b[i];
        }
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 10000; j++) {
                dp[i][j] = 0;
            }
        }
        dp[0][0] = 1;
        for (int i = 0; i < m; i++) {
            for (int k = 0; k <= b[i]; k++) {
                for (int j = 0; j < 10000; j++) {
                    if (j >= k * a[i]) dp[i + 1][j] += dp[i][j - k * a[i]];
                }
            }
        }
        int g;
        cin >> g;
        for (int i = 0, n; i < g; i++) {
            cin >> n;
            cout << dp[m][n] << endl;
        }
    }
}


Measured memory_bytes: 10908