akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

// グローバル変数にすると0で初期化される
int dp[5005][5005];

int main() {

    int N;
    cin >> N;
    
    string S;
    cin >> S;

    // 解説AC
    for(int i = N-1; i >= 0 ; i--) {
        for(int j = N-1; j >= 0; j--) {
            if (S[i] == S[j]) {
                dp[i][j] = dp[i+1][j+1] + 1;
            } else {
                dp[i][j] = 0;
            }
        }
    }

    int res = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i >= j) continue;
            res = max(res, min(dp[i][j], j-i));
        }
    }
    
    cout << res << endl;
    
    // map<string, int> ck;
    // map<string, int> mp;

    // for (int i = 0; i < S.size(); i++) {
    //     for (int j = 1; j <= S.size()-i; j++) {
    //         if (i+j > S.size()) continue;
    //         if (ck[S.substr(i, j)] > i) continue;
    //         if (mp[S.substr(i, j)] >= 2) continue;
    //         mp[S.substr(i, j)] += 1;
    //         ck[S.substr(i, j)] = i + j;            
    //     }
    // }

    // string ans = "";
    // for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    //     if (itr->first.size() * 2 > S.size()) continue;
    //     if (itr->second >= 2 && ans.size() < itr->first.size()) {
    //         ans = itr->first;
    //     }
    //     // cout << itr->first << " " << itr->second << endl;
    // }

    // cout << ans.size() << endl;
    

    return 0;
}

Measured memory_bytes: 98048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long; 
ll N = 200000;
	
ll nc2(ll nm){
	return nm*(nm-1)/2;
}

int main(){
	ll n;	cin >> n;
  	vector<ll> a(n);	rep(i,n) cin >> a.at(i);
  	vector<ll> cor(N+1,0);
  	set<ll> mrk;
  	
  	rep(i,n){
    	cor.at(a.at(i))++;
      	mrk.insert(a.at(i));
    }
  	
  	map<ll,ll> mp;
  	ll sum = 0;
  	for(ll i:mrk) sum += nc2(cor.at(i));
  	for(ll i:mrk) mp[i] = sum-(cor.at(i)-1);
  	
	rep(i,n) cout << mp[a.at(i)] << endl;	

}

Measured memory_bytes: 18560
#include <bits/stdc++.h>
using namespace std;
int main() {
  int s; cin>>s;
  int a[4]={s/1000,s/100%10,s/10%10,s%10};
  for(int p=0;p<1<<3;p++){
    int s=a[0];
    char op[3];
    for(int b=0;b<3;b++){
      if(p&1<<b) s+=a[b+1],op[b]='+';
      else s-=a[b+1],op[b]='-';
    }
    if(s==7){
      cout<<a[0]<<op[0]<<a[1]<<op[1]<<a[2]<<op[2]<<a[3]<<"=7"<<endl;
      return 0;
    }
  }
}



Measured memory_bytes: 3628
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 5100
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
const double PI = acos(-1);

int main(){
    int N;
    cin>>N;
    char S[310][310],temp[310][310];
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++) cin>>S[i][j];
    }
    for(int i=0;i<N;i++){

        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                temp[(j+i)%N][k]=S[j][k];
            }
        }
        bool flag=true;
        for(int j=1;j<N;j++){
            for(int k=0;k<j;k++){
                if(temp[j][k]!=temp[k][j]) flag=false;
            }
        }
        if(flag) ans+=N;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 384
M, D = map(int,input().split())
ans = 0
for m in range(1,M+1):
  if D<=9:continue
  for d in range(10,D+1):
    strd = str(d)
    d10, d1 = int(strd[0]), int(strd[1]) 
    if d10>=2 and d1>=2 and d1*d10==m: ans += 1
print(ans)

Measured memory_bytes: 40816
/*
* @Author: _dp95
* @Date:   2020-04-14 07:44:10
*/
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

const int MAX = 2*1000*1000 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

signed main( ){
  timesaver ;
  string s ;
  cin >> s ;
  int i(0), j(sz(s)-1) ;
  while(s[i]!='A')i++ ;
  while(s[j]!='Z')j--;
  cout << j-i+1 << nl ;
}

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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp(a, b) make_pair(a, b)

const long long MOD = 1000000007;


int main(){
    ll a;
    string s;
    cin >> a >> s;
    if(a >= 3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool q(int x){
    string s;
    cout<<x<<"\n";
    cout.flush();
    cin>>s;
    if(s=="Vacant") exit(0);
    else return (s=="Male"?0:1);
}
int main(){
    int i,n,pas=(1<<21), r=0;
    bool a,b,qr;
    cin>>n;
    a=q(0), b=q(n-1);
    while(pas){
        if(r+pas<n-1){
            qr=q(r+pas);
            if((qr!=b && (r+pas)%2==0) || (qr==b && (r+pas)%2==1))
                r+=pas;
        }
        pas/=2;
    }
    return 0;
}

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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int lhs = c%b;
    int temp = a%b;
    for(int i=0;i<=b-1;i++)
    {
        if( (i*temp)%b  == lhs )
        {
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
#define int long long
signed main(void){
    string s,t,u; cin>>s>>t>>u;
    cout<<char(s[0]+ 'A' - 'a')<<char(t[0]- 'a' + 'A')<<char(u[0]- 'a' + 'A')<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() uint64 {
		sc.Scan()
		i, _ := strconv.ParseUint(sc.Text(), 10, 64)
		return i
	}

	n := in()

	s := ""

	for n != 0 {
		r := n % 26
		if r == 0 {
			s = string('z') + s
			n -= 26
		} else {
			s = string('a'+r-1) + s
			n -= r
		}

		n /= 26
	}

	fmt.Println(s)
}


Measured memory_bytes: 1812
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long ans;
		if((B-A) % 2 == 0)
			ans = (B-A)/2;
		else
			ans = Math.min(A+(B-A)/2, (N-B+1)+(B-A)/2);
		System.out.println(ans);

	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define in inline
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9') {
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
int n,m,rt[200002],head[200002],a[200002],ls[20000002],rs[20000002],ans[200002],u,v,cnt,tot,s[20000002],la,r[200002],val[20000002];
struct edge{
	int to,next;
}e[400002];
inline void bu(re int x,re int y){
	e[++tot].to=y;
	e[tot].next=head[x];
	head[x]=tot;
}
inline int insert(re int v,re int l,re int r,re int x,re int vv) {
	int y=++cnt;
	s[y]=s[x]+1;val[y]=max(val[x],vv);
	if(l==r){
	val[y]=max(val[y],vv);
	return y;}
	ls[y]=ls[x];
	rs[y]=rs[x];
	int mid=(l+r)>>1;
	if(v<=mid)ls[y]=insert(v,l,mid,ls[x],vv);
	else rs[y]=insert(v,mid+1,r,rs[x],vv);
	return y;
}
inline int find(re int p,re int l,re int r,re int x){
	if(!p)return 0;
	if(r<=x)return val[p];
	re int mid=l+r>>1;
	if(x>mid)return max(find(ls[p],l,mid,x),find(rs[p],mid+1,r,x));
	else return find(ls[p],l,mid,x);
}
inline void dfs(re int x,re int y){
	ans[x]=find(rt[y],1,1e9+1,a[x]);
	rt[x]=insert(a[x]+1,1,1e9+1,rt[y],ans[x]+1);
	ans[x]=max(ans[x],ans[y]);
	for(re int i=head[x];i;i=e[i].next)
		if(e[i].to!=y)dfs(e[i].to,x);
}
int main(){
	n=read();
	for(re int i=1;i<=n;++i)a[i]=read();
	for(re int i=1;i<n;++i){
		u=read();
		v=read();
		bu(u,v);
		bu(v,u);
	}
	dfs(1,1);
	for(re int i=1;i<=n;++i)printf("%d\n",ans[i]+1);
}

Measured memory_bytes: 134972
#include<stdio.h>

int main(){

double x,y,S=0;

while(scanf("%lf",&x)!=EOF){
y=x;S=x;
for(int i=2;i<=10;i++){
if(i%2==0){x=y*2;S+=x;y=x;}
else {x=y/3;S+=x;y=x;}
}
printf("%lf\n",S);
}
return 0;
}

Measured memory_bytes: 1076
#include<stdio.h>
int main(){
  int a,b,c,d,ans=0;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a>b){
    ans+=b;
  }else{
    ans+=a;
  }
  if(c>d){
    ans+=d;
  }else{
    ans+=c;
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 1e6+10;
const ll inf = 1e18;

ll power(ll a,ll n){
	if(n==0){
		return 1;
	}
	ll b = power(a,n/2);
	b = b*b%mod;
	if(n%2) b= b*a%mod;
	return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}



int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);
	int a,b;scanf("%d %d",&a,&b);
	if(a<=0 && b>=0){
		printf("Zero\n");
	}else{
		int cnt = 0;
		if(a<0)	cnt-=a;
		if(b<0)	cnt-=(-b+1);
		if(cnt%2){
			printf("Negative\n");
		}else{
			printf("Positive\n");
		}
	}
	return 0;
}



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

class Combination {
public:
    const int MAX = 1110000;
    const int MOD = 1000000007;
    vector<long long> fac, finv, inv;
    Combination() {
        fac.resize(MAX);
        finv.resize(MAX);
        inv.resize(MAX);
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    long long COM(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

void solve() {
    int X, Y;
    cin >> X >> Y;
    if((X + Y) % 3) {
        cout << 0 << '\n';
        return;
    }
    int N = (X + Y) / 3;
    int n = (N - Y + X) / 2;
    int m = (N + Y - X) / 2;
    Combination c;
    long long ans = c.COM(N, n);
    cout << ans << '\n';
}

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


Measured memory_bytes: 26240
#include<bits/stdc++.h>
#define pb push_back
#define rint register int
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=1e5+10;
const int inf=0x3f3f3f3f;

int n,m;
int a[maxn],b[maxn],c[maxn],fa[maxn];
set<int> s;

int Find(int x){
	if(fa[x]!=x) fa[x]=Find(fa[x]);
	return fa[x];
}

void merge(int x,int y){
	int guan=Find(x),huai=Find(y);
	if(guan==huai) return ;
	fa[guan]=huai;
}

int main(){
	scanf("%d%d",&n,&m);
	for(rint i=1;i<=n;++i) fa[i]=i;
	for(rint i=1;i<=m;++i) scanf("%d%d%d",&a[i],&b[i],&c[i]);
	for(rint i=1;i<=m;++i) merge(a[i],b[i]);
	for(rint i=1;i<=n;++i){
		int djjc=Find(i);
		s.insert(fa[i]);
	}
	printf("%d\n",s.size());
	return 0;
}

Measured memory_bytes: 6400
N = int(input())
mins = 101
sums = 0
for i in range(N):
  s = int(input())
  if s % 10:
    mins = min(s, mins)
  sums += s
if sums % 10:
  print(sums)
elif mins <= 100:
  print(sums - mins)
else:
  print(0)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  	ll N;
  	cin>>N;
  	vector<ll> v(N);
  	ll sum=0;
  	for(ll i=0;i<N;i++){
  		cin>>v[i];
  		sum^=v[i];
  	}
    for(int i=0;i<N;i++){
    	cout<<(sum^v[i])<<" ";
    }
   
}

Measured memory_bytes: 4772
import java.util.*;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        Arrays.sort(a);
        long ans = 0;
        if(n%2 == 0){
            int[] b = new int[n];
            b[0] = -1;
            b[n-1] = 1;
            for(int i = 1; i < n-1; i++){
                if(i%2 == 1){
                    b[i] = 2;
                }else{
                    b[i] = -2;
                }
            }
            Arrays.sort(b);
            for(int i = 0; i < n; i++){
                ans += a[i] * b[i];
            }
        }else{
            int[] c = new int[n];
            int[] d = new int[n];
            c[0] = -1;
            c[n-1] = -1;
            d[0] = 1;
            d[n-1] = 1;
            for(int i = 1; i < n-1; i++){
                if(i%2 == 1){
                    c[i] = 2;
                    d[i] = -2;
                }else{
                    c[i] = -2;
                    d[i] = 2;
                }
            }
            Arrays.sort(c);
            Arrays.sort(d);
            long ans1 = 0;
            long ans2 = 0;
            for(int i = 0; i < n; i++){
                ans1 += a[i] * c[i];
                ans2 += a[i] * d[i];
            }
            ans = Math.max(ans1, ans2);
        }
        System.out.println(ans);
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);  
    cin.tie(NULL);
    double d,s;
    int t;
    cin>>d>>t>>s;
    double ans = d/s;
    if(ans <= t)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3736
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n,d; ll A[20][20]; int main()
{
	FAST
	cin>>n>>d;
	FOR(i,0,n) FOR(j,0,d) cin>>A[i][j];
	ll ans=0;
	FOR(i,0,n) FOR(j,i+1,n){
		ll sum=0;
		FOR(k,0,d) sum += (A[i][k]-A[j][k]) * (A[i][k]-A[j][k]); 
		if(sum==0||(ll)sqrtl(sum)*(ll)sqrtl(sum)==sum) ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main(){
	FIO
	
	int n;
	cin >> n;
	if(n / 100 ==  n % 10)puts("Yes");
	else puts("No");
 	return 0; 
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int k,a,b;
	int i=1;
	scanf("%d%d%d",&k,&a,&b);
	if(a>b){
		int tmp=a;
		a=b;
		b=tmp;
	}
	while(k*i<=b){
		if(k*i>=a){
			printf("OK\n");
			return 0;
		}
		i++;
	}
	printf("NG\n");
}

Measured memory_bytes: 1620
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N;
	int[] A;
	int Q;
	int[][] query;
	Map<Integer, Integer> counts;
	long sum = 0;

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		A = new int[N];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < N; ++i) {
			A[i] = Integer.parseInt(tokens[i]);
		}
		Q = Integer.parseInt(in.readLine());
		query = new int[Q][2];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			query[i][0] = Integer.parseInt(tokens[0]);
			query[i][1] = Integer.parseInt(tokens[1]);
		}
		counts = new HashMap<>();
		for (int i = 0; i < N; ++i) {
			if (!counts.containsKey(A[i])) {
				counts.put(A[i], 1);
			} else {
				counts.put(A[i], counts.get(A[i]) + 1);
			}
		}
		for (Integer key : counts.keySet()) {
			sum += (long) key * (long) counts.get(key);
		}
	}

	void calc() {
		// query評価
		for (int i = 0; i < Q; ++i) {
			int B = query[i][0];
			int C = query[i][1];
			if (counts.containsKey(B) && B != C) {
				// sumの更新
				sum += (long) (C - B) * (long) counts.get(B);
				int cNum = 0;
				if (counts.containsKey(C)) {
					cNum = counts.get(C);
				}
				counts.put(C, cNum + counts.get(B));
				counts.remove(B);
				System.out.println(sum);
			} else {
				System.out.println(sum);
			}
		}
	}

	void showResult() {
	}
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
 
//足したり引いたりすると勝手にmodをとってくれる
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
 
//コンビネーションのライブラリ
struct combination {
    //factのなかに階乗を求めている
    //ifactのなかに階乗逆元を求めている
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
 

mint f(int n){
    if (n == 0) return 1;
    mint x = f(n / 2);
    x *= x;
    if (n % 2 == 1) x *= 2;
    return x;
}

mint choose (int n, int a){
    mint x = 1, y = 1;
    rep(i, a){
        x *= n-i;
        y *= i+1;
        
    }
    return x / y;
}

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    
    mint ans = f(n);
    ans -= 1;
    ans -= choose(n,a);
    ans -= choose(n, b);
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 256
N= int(input())

n = list(map(int, input().split()))

if N > 1:
	a =n[0]

	for i in range(N-1):
		if (n[i+1] - n[i]) < -1 :
			print("No")
			exit()
		elif (n[i+1] - n[i]) < 0:
			if(n[i] <= a):
				print("No")
				exit()
			a = n[i] -1
print("Yes")


Measured memory_bytes: 14396
def rootedTrees(node,parent,depth,name,root):
    A.append([node,parent,depth,name,root])
    for i in root:
        if len(B[i][1])!=0:
            rootedTrees(i,node,depth+1,"internal node",B[i][1])
        else:
            rootedTrees(i,node,depth+1,"leaf",B[i][1])

n=int(input())
A,B=[],[]
start=[i for i in range(n)]
for i in range(n):
    node,*root=map(int,input().split())
    B.append([node,root[1:]])
    for j in root[1:]:start.remove(j)

add=start[0]
B=sorted(B, key=lambda x:x[0])
rootedTrees(add,-1,0,"root",B[add][1])
for node,parent,depth,name,root in sorted(A):
    print("node {0}: parent = {1}, depth = {2}, {3}, {4}"
    .format(node,parent,depth,name,root))


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n;
  cin >> n;

  int s = 0, m = n;
  while(m > 0) {
    s += m % 10;
    m /= 10;
  }
  if(n % s == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
int a[5];
int i;
scanf( "%d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4]);


for(i=0;i<5;i++){
  if(a[i]!=i+1){
    printf("%d\n",i+1 );
  }
}
return 0;
}


Measured memory_bytes: 1704
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = cin.nextint;
        var F = new int[N, 10];
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                F[i, j] = cin.nextint;
            }
        }
        var P = new int[N, 11];
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                P[i, j] = cin.nextint;
            }
        }

        long ans = long.MinValue;
        for (int i = 1; i < 1 << 10; i++)
        {
            var H = new int[N];//N点の何個共有しているか
            for (int j = 0; j < 10; j++)
            {
                if ((i >> j & 1) == 1)
                {
                    for (int k = 0; k < N; k++)
                    {
                        if (F[k, j] == 1)
                        {
                            H[k]++;
                        }
                    }
                }
            }
            long tmp = 0;
            for (int j = 0; j < N; j++)
            {
                tmp += P[j, H[j]];
            }
            ans = Math.Max(ans, tmp);

        }
        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11220
#include <iostream>

using namespace std;

int main() {
    int a[4] = {0, 0, 0, 0};
    int i;
    cin >> i;
    while (i--) {
        string s;
        cin >> s;
        if (s == "AC")a[0]++;
        if (s == "WA")a[1]++;
        if (s == "RE")a[2]++;
        if (s == "TLE")a[3]++;
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[3] << endl;
    cout << "RE x " << a[2] << endl;
    return 0;
}

Measured memory_bytes: 3208
N, A, B = list(map(int, input().split()))
S = input()
y, yab = 0, 1

for s in S:
    if(s == 'a'):
        if(y < A + B):
            print("Yes")
            y += 1
        else:
            print("No")
    elif(s == 'b'):
        if(y < A + B and yab <= B):
            print("Yes")
            y += 1
            yab += 1
        else:
            print("No")
    else:
        print("No")

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

#define ASC(a) a.begin(), a.end()		// 昇順ソート 例：sort(ASC(a));
#define DESC(a) a.rbegin(), a.rend()	// 降順ソート 例:sort(DESC(a));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(a) rep(i, n) cin>>a[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;
#define only_unique(vec) vec.erase(std::unique(vec.begin(), vec.end()), vec.end());

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vii;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };


// ────────────────────────────────────────────────────
ll n;
ll k[100100];

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

		if (!n) break;

		ll max_, cnt;
		max_ = cnt = 0;

		rep(i, n) {
			cin >> k[i];
			if (k[i] == 0) cnt++;
			else max_ = max(max_, k[i]);
		}

		if (max_ == 1 || max_ == 0) cout << "NA" << endl;
		else cout << n - cnt + 1 << endl;
	}
}


Measured memory_bytes: 3204
N = int(input())
H_li = list(map(int, input().split(' ')))

def check(H):
  H_max = max(H_li)
  max_indexs = ([i for i, x in enumerate(H_li) if x == H_max])

  if len(max_indexs) > 1:
    max_index = max(max_indexs)
    return max_index
  else:
    return max_indexs[0]


max_index = check(H_li)

S = 0

for i in range(max_index):
  num = max_index - i
  try:
    if max(H_li[:num]) <= H_li[num]:
    	S += 1
  except:
    pass
    
print(S+1)


 

Measured memory_bytes: 3064
#define NOMINMAX
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                                   c > 0 ? i < b : i > b; \
                                   i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep))
	{
		v.push_back(buffer);
	}
	return v;
}

string join(const vector<string>& v, const char* delim = 0) {
	string s;
	if (!v.empty()) {
		s += v[0];
		for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
			if (delim) s += delim;
			s += v[i];
		}
	}
	return s;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
	return accumulate(begin, end, 0ll);
}

template<typename T>
T gcd(T a, T b)
{
	T c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}

template<typename T>
T bit_count(T N) {
	T cnt = 0;
	while (N) {
		if (N & 1) cnt++;
		N >>= 1;
	}
	return cnt;
}

template<typename T>
void print_vec(ostream& ostream, vector<T> a) {
	rep(i, a.size() - 1) ostream << a[i] << " ";
	ostream << a.back() << endl;
}

template<class T>
T pow_n(T x, T n) {
	T res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}

struct Point {
	int y, x;
};

class Solver {
public:
	int H, W;

	bool grid_ok(int y, int x) {
		return 0 <= y && y < H && 0 <= x && x < W;
	}
	
	int a, b;
	
	void solve() {
		cin >> a >> b;
		int res = (a - 1) + (a <= b ? 1 : 0);
		cout << res << endl;
	}

};

signed main()
{
	srand((unsigned int)time(NULL));
	cout << fixed << setprecision(20);
	auto ptr = new Solver();
	ptr->solve();
	delete ptr;
	//while (true) {
	//	if (cin.eof() == true) break;
	//	auto ptr = new Solver();
	//	ptr->solve();
	//	delete ptr;
	//}
	return 0;
}


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

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

#define INF 100000000
#define MOD 10007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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

  ll N,M;
  cin>>N>>M;
  vector<pair<ll,ll> >a(N);
  for(int i=0;i<N;i++){
    cin>>a[i].first>>a[i].second;
  }
  sort(rng(a));
  ll ans=0;
  for(int i=0;i<N;i++){
    ans+=a[i].first*min(M,a[i].second);
    M-=min(M,a[i].second);
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  int a[10] = {0};
  for (int i = 0; i < 10; i++) {
    if (i != 4 && i != 7) {
      char x = s[i];
      a[i] = x - '0';
    }
  }
  int ans = a[0]*10000000+a[1]*1000000+a[2]*100000+a[3]*10000+a[5]*1000+a[6]*100+a[8]*10+a[9];
  if (ans <= 20190430) {
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }
}
      

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}

void Yn(bool f)
{
  cout << (f ? "Yes" : "No") << endl;
}

void yn(bool f)
{
  cout << (f ? "yes" : "no") << endl;
}

void YN(bool f)
{
  cout << (f ? "YES" : "NO") << endl;
}

#define INF 1000000000LL
int n;
ll a[100000];

int main()
{
  cin >> n;
  ll m = INF;
  ll sum = 0;
  int cnt = 0;
  REP(i, n)
  {
    cin >> a[i];
    if(a[i]<0){
      cnt++;
    }
    m = min(m, abs(a[i]));
    sum += abs(a[i]);
  }

  if(cnt%2==1){
    sum -= 2 * m;
    cerr << "hoge m=" << m << "\n";
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1024
/*
Author : N_o_o_B
Created : April 22 2020 22:54:45 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    string s;
    cin >> s;

    int ind = -1;
    int n = sz(s);
    int ans = 0;
    ford(i,n){
        if(s[i]=='A' and ind!=-1){
            ans = max(ans,ind-i+1);
        }
        if(s[i]=='Z' and ind==-1) ind = i;
    }
    cout << ans << endl;


    time_taken();
    return 0;
}

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


N_list = [N,K]

if K == 1:
    print(0)
    
elif N>K:
    print(min(N%K,abs(N%K-K)))
    
elif N == K:
    print(0)
    
else:
    print(min(N,abs(N-K)))



Measured memory_bytes: 2940
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------

int main() {

    string s;
    cin >> s;

    int N = s.size();

    s += "****";

    vector<vector<int>> dp(N + 4, vector<int>(2, -1));
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 2; j++) {
            if (dp[i][j] == -1) continue;
            if (j == 0) {
                if (s[i] != s[i + 1]) dp[i + 1][0] = max(dp[i + 1][0], dp[i][j] + 1);
                dp[i + 2][1] = max(dp[i + 2][1], dp[i][0] + 1);
            }
            if (j == 1) {
                dp[i + 1][0] = max(dp[i + 1][0], dp[i][j] + 1);
                dp[i + 2][1] = max(dp[i + 2][1], dp[i][j] + 1);
            }
        }
    }

    cout << max(dp[N + 1][0], dp[N+1][1]) << endl;

    return 0;
}



























































Measured memory_bytes: 11396
//Hasherd Number

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

int main()
{
  int N, K;
  cin >> N;
  cin >> K;
  int num = 1;
  for (int i = 0; i < N; i++)
  {

    if (num * 2 <= num + K)
    {
      num *= 2;
    }
    else
    {
      num += K;
    }
  }
  cout << num << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; k < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
class UnionFind {
  public:  
    vi Parent;
    UnionFind(int N) {
      Parent = vi(N,-1);
    }
  
      int root(int A) {
      if(Parent[A] < 0) return A;
      return Parent[A] = root(Parent[A]);
    }

      int size(int A) {
      return -Parent[root(A)];
    }
  
      bool connect(int A,int B) {
      A = root(A);
      B = root(B);
      if(A == B) return false;
      if(size(A) < size(B)) swap(A,B);
      Parent[A] += Parent[B];
      Parent[B] = A;
      return true;
    }
};


int main() {
  int N,M;
  cin >> N >> M;
  UnionFind tree = UnionFind(N);
  rep(i,M) {
    int a,b,c;
    cin >> a >> b >> c;
    tree.connect(a-1,b-1);
  }
  vi roots;
  rep(i,N) {
    int x = tree.root(i);
    roots.push_back(x);
  }
  sort(rng(roots));
  roots.erase(unique(rng(roots)),roots.end());
  cout << sz(roots) << endl;
  return 0;
}

Measured memory_bytes: 1276
n = int(input())
s = input()

w_cnt = 0
e_cnt = 0
E = s.count("E")
ans = 10 ** 9

for i in s:
    if i == "E":
        e_cnt += 1
    ans = min(ans, w_cnt + E - e_cnt)
    if i == "W":
        w_cnt += 1

print(ans)

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

int main() {
  int N;
  int A=0,B=0;
  cin>>N;
  vector<int>card(N);
  for(int i=0; i<N; i++){
    cin>>card.at(i);
  }
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      if(card.at(i)<card.at(j)){
        swap(card.at(i),card.at(j));
      }
    }
  }
  for(int i=0; i<N; i++){
    if(i%2==0){
      A+=card.at(i);
    }
    else{
      B+=card.at(i);
    }
  } 
  cout<<A-B<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	uint64_t X;
	uint64_t tamurayukari = 0;
	if (scanf("%" SCNu64, &X) != 1) return 1;
	tamurayukari += 1000 * (X / 500);
	X %= 500;
	tamurayukari += 5 * (X / 5);
	printf("%" PRIu64 "\n", tamurayukari);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(){
    int a,b,k,i,cont=0;

    scanf("%d",&k);

    scanf("%d %d",&a ,&b);

    for(i=a;i<=b;++i){
        if(i%k==0)
            cont++;

        }
        if(cont!=0){
            printf("OK\n");
        } else{
            printf("NG\n");




    }

return 0;
}


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

vector<ll> imos, A;
ll N, M;

void init(){
    cin >> N >> M;
    imos.resize(M);
    A.resize(N);
    for(ll &a : A){
        cin >> a;
        a--;
    }
}

void set_imos(){
    vector<P> v;
    for(ll i = 0; i < N - 1; i++){
        if(A[i] < A[i + 1]){
            v.push_back(P(A[i + 1], A[i + 1] - A[i]));
            imos[A[i + 1]]--;
            imos[A[i]]++;
        }else{
            v.push_back(P(M - 1, M - 1 - A[i]));
            imos[M - 1]--;
            imos[A[i]]++;
            v.push_back(P(A[i + 1], (M - 1 - A[i]) + A[i + 1] + 1));
            imos[A[i + 1]]--;
        }
    }
    for(ll i = M - 1; i > 0; i--) imos[i - 1] += imos[i];
    for(const auto &p : v) imos[p.first] += p.second;
    for(ll i = M - 1; i > 0; i--) imos[i - 1] += imos[i];
}

ll solve(){
    init();
    set_imos();
    ll ret = 0;
    for(ll i = 0; i < N - 1; i++){
        if(A[i + 1] > A[i]){
            ret += A[i + 1] - A[i];
        }else{
            ret += (M - 1) - A[i];
            ret++;
            ret += A[i + 1];
        }
    }
    return ret - *max_element(imos.begin(), imos.end());
}


int main(){
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 7664
n, m, l = map(int, input().split())
a = [[] for _ in range(n)]
b = [[] for _ in range(m)]
  
for i in range(n):
  a[i] = list(map(int, input().split()))
  
for i in range(m):
  b[i] = list(map(int, input().split()))
  
for i in range(n):
  line = []
   
  for j in range(l):
    c = 0
     
    for k in range(m):
      c += a[i][k]*b[k][j]
     
    line.append(str(c))
 
  print(' '.join(line))


Measured memory_bytes: 6244
use std::io::*;
use std::str::FromStr;
use std::cmp::{min, max};

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin_lock = stdin.lock();
    let s = stdin_lock
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let n: i32 = read();

    let mut d: Vec<i32> = (0..n).map(|_| read()).collect();
    d.sort();
    d.dedup();

    println!("{}", d.len());
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
typedef long long ll;
  ll n,k;ll r=0;ll h[400005]={0};ll L[42]={0};ll M=998244353;
int main(){
  cin>>n>>k;h[1]=1;h[2]=-1;
  for(int i=0;i<k;i++)cin>>L[i+1]>>L[21+i];
  for(int i=1;i<n;i++){r+=h[i];if(r<0)r+=100*M;r%=M;
    for(int j=1;j<=k;j++){h[L[j]+i]+=r;h[L[20+j]+i+1]-=r;}
  }  cout<<((r+h[n])+100*M)%M<<endl;}

Measured memory_bytes: 6648
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  ll n,m;
  cin>>n>>m;
  vi h(n);
  rep(i,n) cin>>h[i];
  vi a(m),b(m);
  rep(i,m) cin>>a[i]>>b[i];
  vi p(n,0);
  vector<bool> q(n,true);
  rep(i,m){
    q[a[i]-1]=false;
    q[b[i]-1]=false;
    chmax(p[a[i]-1],h[b[i]-1]);
    chmax(p[b[i]-1],h[a[i]-1]);
  }
  ll ans=0;
  rep(i,n){
    if(h[i]>p[i]) ans++;
    else if(q[i]) ans++;
  }
  out(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 6364