akhauriyash/Code-Regression huggingface dataset:
N, W = map(int, input().split())
VW = [[0,0]]
for _ in range(N):
	VW.append(list(map(int, input().split())))

dp = [[0] * (W+1) for _ in range(N+1)]

for i in range(1,N+1):
	for j in range(1, W+1):
		if VW[i][1] > j:
			dp[i][j] = dp[i-1][j]
		else:
			dp[i][j] = max(dp[i-1][j], dp[i][j-VW[i][1]] + VW[i][0])

print(dp[N][W])


Measured memory_bytes: 15696
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k,q = LI()
    d = LI()
    aa = [LI() for _ in range(q)]

    def f(n,x,m):
        e = [c%m for c in d]
        n -= 1
        s = sum(e)
        t = s * (n//k) + sum(e[:n%k])
        xt = x + t
        z = [1 if c == 0 else 0 for c in e]
        zs = sum(z) * (n//k) + sum(z[:n%k])
        # print(xt, x, m, zs,n%k)
        return n - (xt//m - x//m) - zs

    r = [f(n,x,m) for n,x,m in aa]
    return JA(r, "\n")


print(main())





Measured memory_bytes: 101592
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

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

#define ri(a) scanf("%d", &a)
#define rii(a,b) scanf("%d %d", &a, &b)
#define riii(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define rl(a) scanf("%lld", &a)
#define rll(a,b) scanf("%lld %lld", &a, &b)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second

const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int maxN = 1e5+10; // CAMBIAR ESTE

// GJNM
ll A[maxN], B[maxN], C[maxN];
ll CNT[maxN];

int main(){
	int n, q;
	ri(n);
	ll tot_sum = 0;
	FOR(i,0,n){
		rl(A[i]);
		tot_sum += A[i];
		CNT[A[i]]++;
	}
	ri(q);
	FOR(i,0,q){
		rll(B[i], C[i]);
		tot_sum -= CNT[B[i]]*B[i];
		CNT[C[i]] += CNT[B[i]];
		tot_sum += CNT[B[i]]*C[i];
		CNT[B[i]] = 0;
		printf("%lld\n", tot_sum);
	}


	return 0;
}

Measured memory_bytes: 6944
if __name__ == "__main__":
	while True:
		score = [int(i) for i in input().split()]
		if score[0] == score[1] == score[2] == -1:
			break
		if score[0] == -1 or score[1] == -1:
			print ('F')
		else:
			if score[0] + score[1] >= 80:
				print ('A')
			elif score[0] + score[1] >= 65:
				print ('B')
			elif score[0] + score[1] >= 50:
				print ('C')
			elif score[0] + score[1] >= 30:
				if score[2] == -1:
					print ('D')
				else:
					if score[2] >= 50:
						print ('C')
					else:
						print ('D')
			else:
				print ('F')

Measured memory_bytes: 7744
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll ans=0;
    for(int i=0;i<n-1;i++)
    {
        if(a[i]>a[i+1])
        {
            swap(a[i],a[i+1]);
            ans+=a[i+1]-a[i];
        }
    }
    cout<<ans<<endl;




}
//Alhamdulillah























Measured memory_bytes: 5176
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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

bool isok[100100];
int iserror[100100];
int N,M,p,ans,cnt;
string S;

int main(){
    cin>>N>>M;
    rep(i,100100){
        isok[i]=false;
        iserror[i]=0;
    }
    rep(i,M){
        cin>>p>>S;
        if(S=="AC"&&!isok[p-1]){
            isok[p-1]=true;
            cnt+=iserror[p-1];
        }
        else{
            iserror[p-1]++;
        }
    }
    rep(i,N){
        if(isok[i])ans++;
    }
    cout<<ans<<" "<<cnt<<endl;
    }

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) {
        cin >> a[i];
        --a[i];
    }

    int ans = 0;
    rep(i, N) if (i == a[a[i]])++ ans;

    cout << ans / 2 << endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
 
int main(void){

    char str[100];     			
    char *p;                     

    scanf("%s",str);
    p = &str[0];                
    while (*p != '\0')              
        p++;                          
    while (--p >= str){                   
        putchar(*p);
   }             
    printf("\n");
    return 0;
}

Measured memory_bytes: 524
import java.util.*;

	

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int k=sc.nextInt();

		System.out.println(a+b+c+Math.max(Math.max(a,b),c)*(pow(2,k)-1));
	}
	
	public static int pow(int a,int b){
		int x=1;
		for(int i=0;i<b;i++){
			x*=a;
		}
		return x;
	}
}

Measured memory_bytes: 21716
// Created by sz
#include <bits/stdc++.h>
using namespace std;

long long  N, M, down[100005], up[100005], a[100005];
vector<int> edges[100005];

void dfs(int cur, int pre){
    long long ans = 1;
    
    auto I = find(edges[cur].begin(), edges[cur].end(), pre);
    if (I != edges[cur].end()) edges[cur].erase(I);
    
    for(auto i:edges[cur]){
        if(i != pre){
            dfs(i, cur);
            (ans *= (1ll+ down[i]))%= M;
        }
    }
    down[cur] = ans;
}

void dfs2(int cur){
    int n = edges[cur].size();
    if (n){
        vector<long long> L(n); L[0] = 1;
        vector<long long> R(n); R.back() = 1;
        for (int i=1;i<n;i++) L[i] = L[i-1] * (down[edges[cur][i-1]] + 1) % M;
        for (int i=n-2;i>=0;i--) R[i] = R[i+1] * (down[edges[cur][i+1]] + 1) % M;
        for (int i=0;i<n;i++){
            int y = edges[cur][i];
            up[y] = 1 + up[cur] * L[i] % M * R[i] % M;
            dfs2(y);
        }
    }
    a[cur] = down[cur] * up[cur] % M;
    
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin>>N>>M;
    int x,y;
    for(int i = 0; i< N-1; i++){
        cin>>x>>y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }

    
    dfs(1,0);
    up[1] = 1;
    dfs2(1);
    for(int i = 1; i<=N; i++)cout<<a[i]<<" \n"[i==N];
    return 0;
}



Measured memory_bytes: 19200
s = input()
n = len(s)-1
ans = 0
for i in range(2**n):
    k = 0
    for j in range(n):
        if (i >> j) & 1:
            ans += int(s[k:j+1])
            k = j+1
    ans += int(s[k:])

print(ans)

Measured memory_bytes: 9012
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(void){
    
    int a;
    cin  >> a ;
    if(a%2==0){
        cout << 0.5000000000 << endl;

    } else {
       
        float x;
        x = ((int)a+1.0)/(2.0*(int)a) ;
        cout << x << endl;
    }
   
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
signed main(){
	string s;
	cin>>s;
	ll n=s.size();
	ll cnt=0,ans=0;
	rep(i,n){
		if(s[i]=='B')cnt++;
		else ans+=cnt;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
mod=998244353
inv=pow(2,mod-2,mod)

def xorconv(n,X,Y):
    if n==0:
        res=[(X[0]*Y[0])%mod]
        return res
    x=[X[i]+X[i+2**(n-1)] for i in range(2**(n-1))]
    y=[Y[i]+Y[i+2**(n-1)] for i in range(2**(n-1))]
    z=[X[i]-X[i+2**(n-1)] for i in range(2**(n-1))]
    w=[Y[i]-Y[i+2**(n-1)] for i in range(2**(n-1))]
    res1=xorconv(n-1,x,y)
    res2=xorconv(n-1,z,w)
    former=[(res1[i]+res2[i])*inv for i in range(2**(n-1))]
    latter=[(res1[i]-res2[i])*inv for i in range(2**(n-1))]
    former=list(map(lambda x:x%mod,former))
    latter=list(map(lambda x:x%mod,latter))
    return former+latter

import sys

input=sys.stdin.buffer.readline

N=int(input())

def data():
    edge=[[] for i in range(N)]
    for i in range(int(input())):
        a,b=map(int,input().split())
        if a>b:
            a,b=b,a
        edge[a-1].append(b-1)
    mex=[0 for i in range(N)]
    for i in range(N-1,-1,-1):
        used=[False]*(len(edge[i])+1)
        for pv in edge[i]:
            if mex[pv]<=len(edge[i]):
                used[mex[pv]]=True
        for j in range(len(used)):
            if not used[j]:
                mex[i]=j
                break
    res=[0]*(max(mex)+1)
    for i in range(N):
        res[mex[i]]+=pow(10,18*(i+1),mod)
        res[mex[i]]%=mod

    return res

Xdata=data()
Ydata=data()
Zdata=data()

n=0
m=max(len(Xdata),len(Ydata),len(Zdata))
while 2**n<m:
    n+=1

X=[0 for i in range(2**n)]
Y=[0 for i in range(2**n)]
Z=[0 for i in range(2**n)]

for i in range(len(Xdata)):
    X[i]=Xdata[i]

for i in range(len(Ydata)):
    Y[i]=Ydata[i]

for i in range(len(Zdata)):
    Z[i]=Zdata[i]

YZ=xorconv(n,Y,Z)

ans=0
for i in range(2**n):
    ans+=X[i]*YZ[i]
    ans%=mod

print(ans)


Measured memory_bytes: 106908
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,m,x,y;
bool b[N],c[N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		if(x==1)b[y]=true;
		if(y==n)c[x]=true;
	}
	c[1]=true;
	b[n]=true;
	for(int i=1;i<=n;i++)
		if(b[i]&&c[i]){
			puts("POSSIBLE");
			return 0;
		}
	puts("IMPOSSIBLE");
	return 0;
}

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


int main(){
    int N;
    int L;
    vector<string> s;

    cin>>N>>L;

    for(int i = 0; i < N;i++){
        string t;
        cin>>t;
        s.push_back(t);
    }

    sort(s.begin(),s.end());

    for(int i = 0; i < N;i++){
        cout<<s[i];
    }
    cout<<"\n";
    

}
    


Measured memory_bytes: 256
//https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

int main() {
#if LOCAL&0
  std::ifstream in("./test/sample-2.in");
  //std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  ll N; cin>>N;

  string S;
  REP(i,N){
    S.push_back('a');
  }

  auto dfs = [N](auto&& self, const ll n, string& s, ll t){
    if(n>=N) {
      cout<<s<<endl;
      return;
    }
    //dump(t);
    //FOR(i,0,n+1){
    FOR(i,0,t+1){
      s.at(n)=(char)('a'+i);
      self(self, n+1, s, max(t,i+1));
    }
  };

  dfs(dfs, 0, S, 0);

  return 0;
}

Measured memory_bytes: 1536
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    string s;
    fi>>s;
    int ans = 0;
    int n = s.length();
    for (int i = 0;i < n;++i)
    {
        if (i & 1)
            ans += s[i] == 'g';
        else
            ans -= s[i] == 'p';
    }
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl; }

const LL INF = 1LL << 60;

bool is_ascending_order(vector<LL> vec) {
	bool is_ascending = true;

	for (LL i = 0; i < LL(vec.size()) - 1LL; i++) {
		if (vec[i] > vec[i + 1]) {
			is_ascending = false;
			break;
		}
	}

	return is_ascending;
}

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

	vector<LL> P(N);
	rep(i, N) cin >> P[i];

	if (is_ascending_order(P)) {
		cout << "YES" << endl;
		return 0;
	}

	for (LL i = 0; i < N - 1; i++) {
		for (LL j = i + 1; j < N; j++) {
			vector<LL> P_copy = P;
			swap(P_copy[i], P_copy[j]);
			if (is_ascending_order(P_copy)) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}

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



Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static int inf  = 1<<29;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n    = in.nextInt();
        int[] dp = new int[100001];
        Arrays.fill(dp, inf);
        dp[0] = 0;
        Queue<Integer> q = new PriorityQueue<>();
        q.add(1);
        for(int i = 6; i < 1000000; i *= 6) q.add(i);
        for(int i = 9; i < 1000000; i *= 9) q.add(i);

        Object[] a = q.toArray();
        for(int i = 0; i < dp.length; i++) {
            for(int j = 0; j < a.length; j++) {
                int aj = (int)a[j];
                if(i - aj >= 0) {
                    dp[i] = Math.min(dp[i], dp[i-aj] + 1);
                }
            }
        }

        print(dp[n]);
    }

    static void print(String s) {
        System.out.println(s);
    }

    static void print(int i) {
        System.out.println(i);
    }
}

class E {
    int l, r, w;
    E(int l, int r, int w) {
        this.l = l;
        this.r = r;
        this.w = w;
    }
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

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


int main()
{
	int h,w,d;
	cin >> h >> w >> d;
	P p[h*w]; 
	rep(i,h) rep(j,w){
		int a; cin >> a;
		p[a-1].first = i;
		p[a-1].second = j;
	}
	
	vector<int> sum[d];
	for(int i = 0; i < d; i++) sum[i].emplace_back(0);
	for(int i = 0; i < d; i++){
		for(int j = i+d; j < h*w; j+=d){
			int ax = abs(p[j].first-p[j-d].first);
			int ay = abs(p[j].second-p[j-d].second);
			sum[i].emplace_back(ax+ay+sum[i].back());
			//cout << i << ' ' << j << ' ' << ax << ' ' << ay << endl;
		}
	}

	int q; cin >> q;
	for(int i = 0; i < q; i++){
		int l,r;
		cin >> l >> r;
		l--,r--; //�}�C�i�X!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		cout << sum[r%d][r/d] - sum[l%d][(l)/d] << endl;
	}

	return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    REP(i,s.size()){
        char tmp = s[i] + n;
        if(tmp > 'Z') tmp = 'A' + tmp - 'Z' - 1;
        cout << tmp;
    }
    cout << endl;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
x_list = list(map(int, input().split()))
x_list.sort()
if n >= m:
    print(0)
else:
    l_list = [x_list[i]-x_list[i-1] for i in range(1,m)]
    l_list.sort()
    print(sum(l_list[:m-n]))

Measured memory_bytes: 13968
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 200005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;


struct cmp{
    bool operator() (const pp &a, const pp &b) const {
         int la = a.S-a.F+1;
    int lb = b.S-b.F+1;
    if(la==lb)return a.F<b.F;
    return la>lb;
    }
};


int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t, n=0,c=0;

    string s;
    cin>>s;
    for(int i=0; i<s.length(); i++){
        if(s[i]=='R')c++;
        else{
            n=max(n,c);
            c=0;
        }
    }
    n = max(n,c);
    cout<<n<<endl;

}


Measured memory_bytes: 3608
//https://atcoder.jp/contests/arc096/tasks/arc096_b
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class reverse_range {private:struct I {int x;int operator*() {return x-1;}bool operator!=(I& lhs) {return x>lhs.x;}void operator++() {--x;}};I i, n;public:reverse_range(int n) :i({ 0 }), n({ n }){}reverse_range(int i, int n) :i({ i }), n({ n }){}I& begin() {return n;}I& end() {return i;}};
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }reverse_range operator!(){return reverse_range(*i,*n);}};
constexpr int S = 112345;
int N;
LL C;
LL x[2*S];
LL v[2*S];
LL vs[2*S];
LL sg[2*S],db[2*S];
int main(){
    cin>>N>>C;
    for(int i:range(1,N+1)){
        cin>>x[i]>>v[i];
    }
    x[0]=0;
    v[0]=0;
    N++;
    for(int i:range(N)){
        x[i+N]=C+x[i];
        v[i+N]=v[i];
    }
    for(int i:range(2*N)){
        vs[i+1]=vs[i]+v[i];
    }
    for(int i:range(2*N)){
        sg[i]=-1e18;
        db[i]=-1e18;
    }
    sg[N]=0;
    db[N]=0;
    for(int i:range(N+1,2*N)){
        sg[i]=sg[i-1];
        db[i]=db[i-1];
        const LL vx = vs[i+1]-vs[N];
        const LL cx = x[i]-x[N];
        chmax(sg[i],vx-cx);
        chmax(db[i],vx-2*cx);
        //cout<<vx<<"  "<<cx<<endl;
    }
    for(int i:!range(1,N)){
        sg[i]=sg[i+1];
        db[i]=db[i+1];
        const LL vx = vs[N]-vs[i];
        const LL cx = x[N]-x[i];
        chmax(sg[i],vx-cx);
        chmax(db[i],vx-2*cx);
    }
    LL ret=0;
    for(int i:range(N)){
        //cout<<sg[N+i]<<" "<<db[i+1]<<endl;
        chmax(ret,db[N+i]+sg[i+1]);
        chmax(ret,sg[N+i]+db[i+1]);
    }
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 8704
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    int n;
    int A[4][3][10];
    int n1,n2,n3,n4;
    
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                A[i][j][k]=0;
            }
        }
    }
    
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d %d %d %d",&n1,&n2,&n3,&n4);
        A[n1-1][n2-1][n3-1]+=n4;
        if(A[n1-1][n2-1][n3-1]<0)A[n1-1][n2-1][n3-1]=0;
        if(A[n1-1][n2-1][n3-1]>9)A[n1-1][n2-1][n3-1]=9;
    }
    
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout<<' '<<A[i][j][k];
            }
            cout<<endl;
        }
        if(i!=3)cout<<"####################"<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3148
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
ll ppow(ll x, ll n) {
	ll ans = 1;
	while (n > 0) {
		if ((n & 1) == 1)ans = ans * x;
		x = x * x;
		n >>= 1;
		x %= mod;
		ans %= mod;
	}
	return ans;
}
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll sz, fact[N], inv[N];
void setinv() {
	fact[0] = 1; inv[0] = 1;
	for (int i =1; i <= sz; i++) {
		fact[i] = (fact[i - 1] * i) % mod;  //階乗を求める
		inv[i] = ppow(fact[i], (ll)mod - 2) % mod; // フェルマーの小定理で逆元を求める
	}
}
ll conv(ll r) {//nCr
	return fact[sz] * inv[r] % mod * inv[sz - r] % mod;
}
int a,b,c,x,v[1000000];
int main() {
	cin >> a >> b >> c >> x;
	rep(i, a+1)rep(j, b+1)rep(k, c+1) {
		v[i * 500 + j * 100 + k * 50]++;
	}
	cout << v[x] << endl;
	return 0;
}

Measured memory_bytes: 2432
#include<stdio.h>
int main(void)
{
	int a,b,x,y;
	scanf("%d %d",&a,&b);
	y=(a+b)/2;
	x=a+b;
	if(x%2==1){
			y++;
			printf("%d\n",y);
	}
	else printf("%d\n",y);
	return 0;
}	

Measured memory_bytes: 128
import re

def resolve(patterns, text):
    res = "UNRESTORABLE"
    for i in reversed(range(len(patterns) - len(text) + 1)):
        if re.search(patterns[i:i+len(text)], text):
            res = patterns[:i] + text + patterns[i+len(T):]
            res = res.replace('.', 'a')
            return res
    return res

S_dash = raw_input().replace('?', '.')
T = raw_input()

print resolve(S_dash, T)

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

using namespace std;

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

    int a, b;

    cin >> a >> b;

    if (a == 1) a += 13;
    if (b == 1) b += 13;

    cout << (a == b ? "Draw" : (a < b ? "Bob" : "Alice")) << endl;

    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum mod = 10L^^9 + 7;
enum inf = 10^^9;

void main() {
    int n;
    scan(n);
    string s;
    scan(s);
    int q;
    scan(q);

    auto k = readln.split.to!(int[]);

    foreach (ki ; k) {
        auto ans = solve(n, s, ki);
        writeln(ans);
    }
}


long solve(int n, string s, int k) {
    long ans;
    long cntd, cntm, dm;

    foreach (i ; 0 .. n) {
        if (s[i] == 'C') {
            ans += dm;
        }
        
        if (i >= k - 1) {
            if (s[i - (k-1)] == 'D') {
                dm -= cntm;
                cntd--;
            }
            else if (s[i - (k-1)] == 'M') {
                cntm--;
            }
        }

        if (s[i] == 'D') {
            cntd++;
        }
        else if (s[i] == 'M') {
            dm += cntd;
            cntm++;
        }
    }

    return ans;
}


























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 4348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		sc.close();
		System.out.println(str.substring(0, 5) + " " + str.substring(6, 13) + 
				" " + str.substring(14, 19));
	}
}

Measured memory_bytes: 22612
#include<stdio.h>

using namespace std;

struct Node{
    int parent;
    int left;
    int right;
};

const int NIL = -1;

Node nodes[100000];

int main(){
    int n;
    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        nodes[i].parent = nodes[i].left = nodes[i].right = NIL;
    }

    for(int i = 0; i < n; i++){
        int id;
        scanf("%d", &id);

        int k;
        scanf("%d", &k);

        int prev = NIL;

        for(int j = 0; j < k; j++){
            int c;
            scanf("%d", &c);

            if(j == 0){
                nodes[id].left = c;
            }

            nodes[c].parent = id;

            if(j == k-1){
                nodes[c].right = NIL;
            }

            if(prev != NIL){
                nodes[prev].right = c;
            }

            prev = c;
        }
    }

    for(int i = 0; i < n; i++){
        printf("node ");
        printf("%d", i);

        printf(": parent = ");
        printf("%d", nodes[i].parent);

        int depth = 0;
        int current = i;
        while(nodes[current].parent != NIL){
            current = nodes[current].parent;
            depth++;
        }
        printf(", depth = ");
        printf("%d", depth);

        if(nodes[i].parent == NIL){
            printf(", root, [");
        }
        else if(nodes[i].left == NIL){
            printf(", leaf, [");
        }
        else{
            printf(", internal node, [");
        }
        if(nodes[i].left != NIL){
            printf("%d", nodes[i].left);
            int current = nodes[i].left;
            while(nodes[current].right != NIL){
                printf(", ");
                printf("%d", nodes[current].right);
                current = nodes[current].right;
            }
        }
        printf("]\n");
    }
}


Measured memory_bytes: 3864
nums = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(nums[k-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string num;
    cin >> num;
    function<long long(string)> solve = [&] (string x) -> long long {
        ll ans = stoll(x);
        for (int i = 0; i < (int)x.size() - 1; ++ i) {
            string bar = x.substr(i + 1);
            ans += (1LL << ((int)bar.size() - 1)) * (ll)stoll(x.substr(0, i + 1)) + solve(bar);
        }
        return ans;
    };
    cout << solve(num);
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

void dfs(int from) {
	int c = 1;
	for (auto t : tree[from]) {
		c = c != color[from] ? c : c + 1;
		color[t] = c;
		colorMap[make_pair(from, t)] = c;
		m = max(c, m);
		dfs(t);
		c++;
	}
}

int main() {
	int N, K;
	cin >> N >> K;
	vector<ll>H(N);
	for (int i = 0; i < N;++i) {
		cin >> H[i];
	}
	sort(H.rbegin(), H.rend());
	ll ans = 0;
	if (N <= K)ans = 0;
	else {
		for (int i = K; i < N;++i) {
			ans += H[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4096
#include<cstdio>

using namespace std;

long long dp[5000];

const long long MOD=998244353;
long long fast_pow(long long b,long long p){long long ans=1;while(p){if(p&1)ans=ans*b%MOD;b=b*b%MOD;p>>=1;}return ans;}
long long INV(long long b){return fast_pow(b,MOD-2);}

int a[5000];

int main()
{
	int n=0,s=0;scanf("%d%d",&n,&s);for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	dp[0]=fast_pow(2,n);
	for(int i=1;i<=n;i++)
	{
		for(int j=s;j>=a[i];j--)
		{
			dp[j]=(dp[j]+dp[j-a[i]]*INV(2))%MOD;
		}
	}
	printf("%lld",dp[s]);
}

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

int main()
{
  int n;
  cin >> n;
  
  if(n <= 111){
    cout << 111 << endl;
  }else if(n <= 222){
    cout << 222 << endl;
  }else if(n <= 333){
    cout << 333 << endl;
  }else if(n <= 444){
    cout << 444 << endl;
  }else if(n <= 555){
    cout << 555 << endl;
  }else if(n <= 666){
    cout << 666 << endl;
  }else if(n <= 777){
    cout << 777 << endl;
  }else if(n <= 888){
    cout << 888 << endl;
  }else{
    cout << 999 << endl;
  }
}

Measured memory_bytes: 3640
A, B, C, X, Y = map(int, input().split())
ans = float('inf')
for i in range(min(X,Y)+1):
    nedan = A*(X-i)+B*(Y-i)+2*i*C
    ans = min(ans,nedan)

print(min(ans,C*(max(2*X,2*Y))))

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

using namespace std;

int a[10], n, A, B, C;
vector <int> va, vb, vc;
int tot = INT_MAX;
void calc(int dep)
{
	if (dep > n)
	{
		if (va.empty() || vb.empty() || vc.empty()) return;
		int cnt = 0;
		if (va.size() > 1) cnt += (va.size() - 1) * 10;
		if (vb.size() > 1) cnt += (vb.size() - 1) * 10;
		if (vc.size() > 1) cnt += (vc.size() - 1) * 10;
		int sa(0), sb(0), sc(0);
		for (int i = 0; i < va.size(); i++)
			sa += va[i];
		for (int i = 0; i < vb.size(); i++)
			sb += vb[i];
		for (int i = 0; i < vc.size(); i++)
			sc += vc[i];
		cnt += abs(sa - A) + abs(sb - B) + abs(sc - C);
		if (cnt < tot) tot = cnt;
		return;
	}
    calc(dep + 1);
	va.push_back(a[dep]);
	calc(dep + 1);
	va.pop_back();
	vb.push_back(a[dep]);
	calc(dep + 1);
	vb.pop_back();
	vc.push_back(a[dep]);
	calc(dep + 1);
	vc.pop_back();
}
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> A >> B >> C;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	calc(1);
	cout << tot << endl;

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};



ll n,q;
string s;
ll Q_MAX=2e5;
vector<char> t(Q_MAX),d(Q_MAX);

bool lcheck(ll m){
  if(m==-1)
    return true;

  char now=s[m];
  REP(i,q){
    if(t[i]==now){
      if(d[i]=='L')
        m--;
      else
        m++;

      if(m==-1)
        return true;
      if(m==n)
        return false;

      now=s[m];
    }
  }

  return false;
}


bool rcheck(ll m){
  if(m==n)
    return true;

  char now=s[m];
  REP(i,q){
    if(t[i]==now){
      if(d[i]=='L')
        m--;
      else
        m++;

      if(m==n)
        return true;
      if(m==-1)
        return false;

      now=s[m];
    }
  }

  return false;
}



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

  cin>>n>>q;
  cin>>s;
  REP(i,q)cin>>t[i]>>d[i];

  ll ok=-1;
  ll ng=n;
  while(abs(ng-ok)>1){
    ll mid=(ng+ok)/2;
    if(lcheck(mid))
      ok=mid;
    else
      ng=mid;
  }

  ll l=ok;


  ok=n;
  ng=-1;
  while(abs(ok-ng)>1){
    ll mid=(ng+ok)/2;
    if(rcheck(mid))
      ok=mid;
    else
      ng=mid;
  }

  ll r=ok;
  ll ans=n-(l+1)-(n-r);
  cout<<ans<<endl;

}



Measured memory_bytes: 4028
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    double n, sum, aveC, aveF, ansC = 0, ansF = 0;
    cin >> n;
    vector<int> x(n);
    rep(i, n) {
        cin >> x[i];
        sum += x[i];
    }
    aveC = ceil(sum / n);
    aveF = floor(sum / n);
    rep(i, n) {
        ansC += pow(x[i] - aveC, 2);
        ansF += pow(x[i] - aveF, 2);
    }
    COUT(min(ansC, ansF));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N,M;
vector<int> s[10];
vector<int> p(10,0);
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>M;
    rep(i,0,M){
        int k;
        cin>>k;
        s[i].resize(k);
        rep(j,0,k){
            cin>>s[i][j];
            s[i][j]--;
        }
    }
    rep(i,0,M) cin>>p[i];
    int ans=0;
    rep(i,0,1<<N){
        bool t=true;
        rep(j,0,M){
            int res=0;
            for(auto &in: s[j]){
                res+=(i>>in)&1;
            }
            if(res%2!=p[j]) t=false;
        }
        if(t) ans++;
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#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 all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;

int main()
{
    cin >> n;
    ll kisu = 1;
    rep(i,n){
        int a;
        cin >> a;
        if(a % 2 == 0) kisu *= 2;
        else kisu *= 1;
    }
    ll ans = pow(3,n);
    ans -= kisu;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
function Main(input) {
    var N = parseInt(input[0], 10);
    var a = input.slice(1).map(w => parseInt(w, 10));

    var block = 0;
    var num = 1;

    for (var i = 0; i < N; i++) {
        if (a[i] === num) {
            num++;
        } else {
            block++;
        }
    }

    console.log(num === 1 ? -1 : block);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 39008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.regex.Pattern;

public class Main {
    public void solve(Stdin stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int h = stdin.nextInt();
        int w = stdin.nextInt();
        int[][] a = new int[h][w];
        int[][] b = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[i][j] = stdin.nextInt();
            }
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                b[i][j] = stdin.nextInt();
            }
        }

        int max = (h + w) * 80;
        boolean[][][] dp = new boolean[h][w][max + 1];
        dp[0][0][Math.abs(a[0][0] - b[0][0])] = true;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                for (int k = 0; k <= max; k++) {
                    if (!dp[i][j][k]) {
                        continue;
                    }
                    if (i < h - 1) {
                        int l = Math.abs(a[i + 1][j] - b[i + 1][j]);
                        dp[i + 1][j][Math.abs(k - l)] = true;
                        dp[i + 1][j][Math.abs(k + l)] = true;
                    }
                    if (j < w - 1) {
                        int l = Math.abs(a[i][j + 1] - b[i][j + 1]);
                        dp[i][j + 1][Math.abs(k - l)] = true;
                        dp[i][j + 1][Math.abs(k + l)] = true;
                    }
                }
            }
        }

        for (int k = 0; k <= max; k++) {
            if (dp[h - 1][w - 1][k]) {
                stdout.println(k);
                break;
            }
        }
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        Stdin stdin = new Stdin();
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }

    public static class Stdin {
        private Deque<String> queue;
        private BufferedReader stdin;
        private Pattern delimiter;

        public Stdin() {
            queue = new ArrayDeque<>();
            stdin = new BufferedReader(new InputStreamReader(System.in));
            delimiter = Pattern.compile(" ");
        }

        public String next() throws IOException {
            if (queue.isEmpty()) {
                delimiter.splitAsStream(stdin.readLine()).forEach(queue::addLast);
            }
            return queue.removeFirst();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }
    }
}


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

int main(int argc, char const *argv[])
{
	int n; ll z, w; cin >> n >> z >> w;
	vector<ll> a(n); {
		rep(i, n) cin >> a[i];
	}

	if (n == 1) {
		printf("%lld\n", abs(a[0] - w));
		return 0;
	}

	ll ans = max(abs(a[n - 1] - w), abs(a[n - 1] - a[n - 2]));
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int n;
	cin>>n;
	int i,j;
	int ans=0,tmp;
	vector<int> v(n,0);
	rep(i,n)cin>>v[i];
	sort(v.begin(),v.end());
	rep(i,n){
		tmp=v[i];
		j=0;
		while(i+j<n&&v[i+j]==v[i]){
			j++;
		}
		if(j>tmp)ans+=j-tmp;
		else if(j<tmp)ans+=j;
		i+=j-1;
//		cout<<ans<<endl;
	}
	cout<<ans<<endl;
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
return 0;}











Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;
const int INF = 100000000;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    int n;
    cin >> n;
    rep(i, n){
        int a[3];
        cin >> a[0] >> a[1] >> a[2];
        sort(a, a+3);
        if(a[2]*a[2] == (a[1]*a[1] + a[0]*a[0])){
            cout << "YES" << endl;
        }else{
            cout << "NO" <<endl;
        }
    }
    return 0;    
}

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

int main(){
	int a,b,calc;
	int i=0,dig=1,check=0;

	cin >>a >>b;
	for(int i=1;i<=b;i*=10)dig=i;
	calc=a*dig*10+b;
	while(calc>i*i){
		i++;
		if(calc==i*i)check=1;
	}
	if(check==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#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<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
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, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, 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) {
	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 gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
vector<int>a;
signed main() {
	int n;
	cin>>n;
	for(int i=3;i<=55555&&n;i++){
		if(i%5!=1) continue;
		for(int j=2;j*j<=i;j++){
			if(i%j==0) goto loop;
		}
		n--;
		a.push_back(i);
		loop:;
	}
	for(int i=0;i<a.size();i++){
		if(i<a.size()-1) cout<<a[i]<<" ";
		else cout<<a[i]<<endl;
	}
}


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

using namespace std;

int main()
{
  int N, d;
  cin >> N >> d;
  int p[1001];
  for(int i = 0; i < N; i++) cin >> p[i];
  sort(p, p + N);
  reverse(p, p + N);
  int ans = -d + p[0];
  for(int i = 1; i < N; i++) {
    if(ans < ans + p[i] - d) ans += p[i] - d;
    else break;
  }
  if(ans <= 0) cout << "kusoge" << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1180
object Main extends App {
  val Array(n,m) = io.StdIn.readLine.split(' ').map(_.toInt)

  val abs = (for (i <- 1 to n) yield io.StdIn.readLine.split(' ').map(_.toInt)).sortWith((ab0,ab1) => ab0(0) < ab1(0))

  var bought = 0
  var budget = 0L
  var i = 0

  while (bought < m) {
    if (bought + abs(i)(1) <= m) {
      bought += abs(i)(1)
      budget += abs(i)(1)*abs(i)(0).toLong
    } else if (bought + abs(i)(1) > m) {
      val necessary = m - bought
      bought += necessary
      budget += necessary*abs(i)(0).toLong
    }
    i += 1
  }

  val out = budget

  println(out)
}


Measured memory_bytes: 51168
import java.util.Scanner;

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

        int K = scanner.nextInt();

        for (int i = 0 ; i < K ; i++) {
            System.out.print("ACL");
        }
        System.out.println();
    }
}


Measured memory_bytes: 35756