akhauriyash/Code-Regression huggingface dataset:
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

struct UnionFind {
	std::vector<int> _parent;
	std::vector<int> _size;
	UnionFind(int size) : _parent(size, -1), _size(size, 1) { }
	void unite(int a, int b) {
		int ra = root(a), rb = root(b); if (ra == rb) { return; }
		if (_size[ra] >= _size[rb]) { _parent[rb] = ra, _size[ra] += _size[rb]; } else { _parent[ra] = rb, _size[rb] += _size[ra]; }
	}
	int root(int a) {
		int p = _parent[a];
		if (p < 0) { return a; }
		while (_parent[p] >= 0) { p = _parent[p]; }
		return _parent[a] = p;
	}
	int size(int a) { return _size[root(a)]; }
};

void solve(int N, int M, std::vector<int> &A, std::vector<int> &B) {
	UnionFind uf(N);
	for (int i = 0; i < M; ++i) {
		uf.unite(A[i], B[i]);
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans = max(ans, uf.size(uf.root(i)));
	}
	cout << ans << endl;
}

int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	std::vector<int> A(M), B(M);
	for (int i = 0; i < M; i++) {
		scanf("%d %d", &A[i], &B[i]);
		A[i]--, B[i]--;
	}
	solve(N, M, A, B);
	return 0;
}


Measured memory_bytes: 6436
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mm=1000000007;
int i,j,k,n,m,ans;
int main(){
	scanf("%d%d",&n,&m);
	if (n<m) swap(n,m);
	if (n>m+1){
		puts("0");return 0;
	}
	if (n==m){
		for (ans=2,i=1;i<=n;i++) ans=(ll)ans*(ll)i%mm*(ll)i%mm	;
	}else{
		for (ans=i=1;i<=n;i++) ans=(ll)ans*(ll)i%mm;
		for (i=1;i<=m;i++) ans=(ll)ans*(ll)i%mm;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll h,w;
	cin>>h>>w;
	if(h==1||w==1)cout<<"1"<<endl;
	else cout<<(w/2+w%2)*(h/2+h%2)+(w/2)*(h/2)<<endl;

	return 0;

}


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

// シンプルに変更する
int main() {
    int X, N;
    cin >> X >> N;

    if (N == 0) {
        cout << X;
        return 0;
    }

    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }

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

    int index = -1;
    for (int i = 0; i < N; i++) {
        if (p[i] == X) {
            index = i;
            break;
        }
    }
    if (index == -1) {
        cout << X;
        return 0;
    }

    // 念のため101
    for (int i = 1; i <= 101; i++) {
        if (index - i < 0) {
            cout << X - i;
            return 0;
        }
        if (X - i != p[index - i]) {
            cout << X - i;
            return 0;
        }
        if (index + i >= N) {
            cout << X + i;
            return 0;
        }
        if (X + i != p[index + i]) {
            cout << X + i;
            return 0;
        }
    }
}


Measured memory_bytes: 3632
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define MAX_EDGE_LEN 0x100

bool paint[MAX_EDGE_LEN][MAX_EDGE_LEN];

void init_paint()
{
  for(int x = 0; x < MAX_EDGE_LEN; x++) {
    for(int y = 0; y < MAX_EDGE_LEN; y++) {
      paint[x][y] = false;
    }
  }
}

bool has_isolated_paint(int height, int width)
{
  for(int x = 1; x <= height; x++) {
    for(int y = 1; y <= width; y++) {
      if(!paint[x][y]) {
        continue;
      }
      if(!paint[x-1][y] && !paint[x][y-1] &&
         !paint[x+1][y] && !paint[x][y+1]) {
        return true;
      }
    }
  }
  return false;
}

int main()
{
  int height, width;
  char lf;
  scanf("%d %d%c", &height, &width, &lf);
  for(int x = 1; x <= height; x++) {
    for(int y = 1; y <= width; y++) {
      char ch = getchar();
      if(ch == '.') {
        paint[x][y] = false;
      } else if(ch == '#') {
        paint[x][y] = true;
      } else {
        fprintf(stderr, "Unexpected char '%c'\n", ch);
        exit(1);
      }
    }
    getchar(); // remove LF
  }
  if(has_isolated_paint(height, width)) {
    puts("No");
  } else {
    puts("Yes");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;


int main()
{
	int X, H;

	cin >> X;

	H = X / 500 * 1000;
	H = H + (X % 500) / 5 * 5;

	cout << H;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int n;
ll l[100005];
ll a, b;

int main() {
  scanf("%d%lld%lld", &n, &a, &b);
  for(int i = 0; i < n; i++) {
    scanf("%lld", &l[i]);
  }
  ll lhs = 1;
  ll rhs = 1000000000;
  ll inc = a-b;
  while(lhs != rhs) {
    ll mid = (lhs+rhs)/2;
    ll need = 0;
    for(int i = 0; i < n; i++) {
      need += max(0LL, (l[i] - b * mid + inc - 1) / inc);
    }
    if(need > mid) {
      lhs = mid+1;
    }
    else {
      rhs = mid;
    }
  }
  printf("%lld\n", lhs);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;cin >> n >> k;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	ll ans = 0;
	rep(i,n){
		ll cnt1 = 0,cnt2 = 0;
		for(int j = i + 1; j < n; j++){
			if(a.at(j) < a.at(i)) cnt1++;
		}
		for(int j = i - 1; j >= 0; j--){
			if(a.at(j) < a.at(i)) cnt2++;
		}
		ans += k * (k + 1) / 2 % mod * cnt1;
		ans %= mod;
		if(cnt2 > 0) ans += k * (k - 1) / 2 % mod * cnt2;
		ans %= mod;
	}
	cout << ans << endl;
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int A,B,C; cin >> A>>B>>C;
    Yes(A<=C&&C<=B);    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int h, w;
   cin >> h >> w;
   string board[50];

   for(int i = 0; i < h; i++){
      cin >> board[i];
   }

   // 解法
   // #ではなく.を中心に考える.
   // 二重forで.を探索し, その周辺8近傍で#を検出する度にnum++する.
   // 8近傍を探索する際は, dy, dx8点に関してfor文を回して#を検出する.
   const int dx[8] = {1,0,-1,0,1,-1,-1,1};
   const int dy[8] = {0,1,0,-1,1,1,-1,-1};

   for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
         // .を検出したいので#の場合はcontinue
         if(board[i][j] == '#'){continue;}

         int num = 0;
         for(int d = 0; d < 8; d++){
            const int ni = i + dy[d];
            const int nj = j + dx[d];

            // indexがrange外の場合もcontinue
            if(ni < 0 or h <= ni){continue;}
            if(nj < 0 or w <= nj){continue;}
            // .周りに#を検出したらnum++
            if(board[ni][nj] == '#'){num++;}
         }
         // .の座標にnumを代入
         board[i][j] = char(num + '0');
      }
   }

   for(int i = 0; i < h; i++){
      cout << board[i] << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,q,d[1<<18],a,b,c,e[1<<17];
void m(int l,int r,int k){
	if(r<=a||b<=l)return;
	if(a<=l&&r<=b)d[k]=q;
	else{m(l,(l+r)/2,k*2+1);m((l+r)/2,r,k*2+2);}
}
int main(){
	cin>>a>>q;n=2;while(n<a)n*=2;a=2*n;
	while(a--)d[a]=114514;e[114514]=INT_MAX;
	while(q--){
		cin>>a;
		if(a){cin>>a;a+=n-1,b=d[a];
			while(a)a=(a-1)/2,b=min(b,d[a]);
			cout<<e[b]<<endl;
		}
		else{cin>>a>>b>>c;b++,e[q]=c;m(0,n,0);}
	}
	return 0;
}

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

Measured memory_bytes: 9828
n,k=map(int,input().split())
mod=10**9+7
L=[]
ans=0
for i in range(1,k+1):
  L.append(pow(k//i,n,mod))
for i in range(k,0,-1):
  x=L[i-1]
  for j in range(1,k//i):
    x-=L[i*(j+1)-1]
    x+=mod
    x%=mod
  L[i-1]=x
  ans+=x*i
  ans%=mod
print(ans)

Measured memory_bytes: 73884
import itertools
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
li = list(itertools.combinations_with_replacement(range(1, m+1), n))
ans = 0
for l in li:
    result = 0
    for line in abcd:
        if (l[line[1]-1]-l[line[0]-1]) == (line[2]):
            result += line[3]
    ans = max(ans, result)
print(ans)


Measured memory_bytes: 21528
import math

A, B, C, D = map(int, input().split())


def not_multiple_of_c_and_d(x: int, c: int, d: int):
    lcm_cd = c * d // math.gcd(c, d)
    c_no_baisu = x // c
    d_no_baisu = x // d
    cd_no_baisu = x // lcm_cd
    return x - (c_no_baisu + d_no_baisu - cd_no_baisu)


ans = not_multiple_of_c_and_d(B, C, D) - not_multiple_of_c_and_d(A-1, C, D)
print(ans)


Measured memory_bytes: 62152
#include<stdio.h>
#include<string.h>
int main()
{
    char ss[100005];
    while(~scanf("%s",ss))
    {
        int i,flag=0;
        for(i=0;i<strlen(ss)-1;i++)
        {
            if(ss[i]==ss[i+1])
            {
                printf("%d %d\n",i+1,i+2);
                flag=1;
                break;
            }
            else if(ss[i]==ss[i+2])
            {
                printf("%d %d\n",i+1,i+3);
                flag=1;
                break;
            }
        }
        if(flag==0)printf("-1 -1\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=100111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

/*
vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}
*/
ll kaizyou(ll x){
	ll ans=0;
	rep(i,1,x+1)ans+=i;
	if(x==0)ans=1;
	return ans;
}

int main() {
	int n,m;
	cin>>n>>m;
	int a,b;
	vi v[M];
	priority_queue<int> que;
	rep(i,0,n){
		cin>>a>>b;
		if(a>m)continue;
		v[a].push_back(b);
	}
	ll ans=0;
	rep(i,1,m+1){
		for(auto x:v[i])
			que.push(x);
		if(!que.empty()){
			ans+=que.top();
			que.pop();
		}
	}
	print(ans);
}

Measured memory_bytes: 5632
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long arr[]=new long[n];
		HashMap<Long,Integer> map=new HashMap<>();
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextLong();
			if(map.containsKey(arr[i]))
			{
				map.put(arr[i],map.get(arr[i])+1);
			}
			else
				map.put(arr[i],1);
			
		}
		long c=0;
		for(Map.Entry<Long, Integer> i:map.entrySet())
		{
			long k=i.getKey();
			long val=(long)i.getValue();
			if(k==1)
				c+=(Math.abs(k-val));
			else if(k==0)
				c+=val;
			else
			c+=(val%k);
		}
		
		System.out.println(c);
	}
 
}


Measured memory_bytes: 66092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll k, a[55] = {};
    cin >> k;
    for (int i = 0; i < 50; i++) a[i] = k / 50 + 50 - 1;
    for (int i = 0; i < k % 50; i++) {
        for (int j = 0; j < 50; j++) a[j]--;
        a[i] += 51;
    }
    cout << 50 << '\n';
    for (int i = 0; i < 50; i++) cout << a[i] << ' ';
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var n = Integer.parseInt(br.readLine());
      final var a = new boolean[n];
      for (int i = 0; i < n; i++) {
        final var line = br.readLine().split(" ");
        a[i] = Integer.parseInt(line[0]) == Integer.parseInt(line[1]);
      }

      for (int i = 3; i <= n; i++) {
        if (a[i - 3] && a[i - 2] && a[i - 1]) {
          System.out.println("Yes");
          return;
        }
      }

      System.out.println("No");
    }
  }
}


Measured memory_bytes: 32624
N, M = map(int,input().split())
adj = [set() for i in range(N+1)]
for i in range(M):
	u, v = map(int,input().split())
	adj[u].add(v)
	adj[v].add(u)

def good(p):
	for i in range(N-1):
		if p[i+1] not in adj[p[i]]:
			return False
	return True

ans = 0

from itertools import permutations
for p in permutations(range(2,N+1)):
	if good([1]+list(p)):
		ans += 1

print(ans)

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, d;
	cin >> n >> d;
	vector<VI> a(n, vector<int>(d));
	FOR(i, 0, n) FOR(j, 0, d) cin >> a[i][j];
	
	int ans = 0;
	FOR(i, 0, n) FOR(j, i + 1, n)
	{
		int C = 0;
		FOR(k, 0, d) C += (a[i][k] - a[j][k])  * (a[i][k] - a[j][k]);
		int s = sqrt(C);
		ans += s * s == C;
	}
	
	cout << ans;
	
	
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
const int maxn = 1e5 + 10;
int a[maxn];
int main()
{
	int s;
	while (~scanf("%d", &s)) {
		int res = 0, ans = 0;
		if (s == 4 || s == 2 || s == 1) {
			puts("4");
			continue;
		}
		a[1] = s;
		for (int i = 2; i <= 200; i++) {
			if (a[i - 1] & 1) {
				a[i] = a[i - 1] * 3 + 1;
			}
			else {
				a[i] = a[i - 1] / 2;
			}
			if (a[i] == 4) {
				ans = i; break;
			}
		}
		//cout << a[114] << endl << a[111]<< endl;
		ans += 3;
		cout << ans << endl;
	}
	return 0;
}
//_CRT_SECURE_NO_WARNINGS
//final 4;


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

int n, a[202020];

int main()
{
    cin >> n;
    rep(i, n) cin >> a[i];

    ll res = n;
    int x = a[0], right = 0;
    for(int i = 0; i < n; i++)
    {
        while(right + 1 < n && (x + a[right + 1]) == (x ^ a[right + 1]))
        {
            x += a[right + 1];
            right++;
        }
        res += right - i;
        x ^= a[i];
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

int main(){
    signed int n, m, a, b, c, d;
    char temp[3];
    cin >> n >> m;
    vector<vector<int>> map(n, vector<int>(n, 2000000));
    for(int i = 0;i<m;i++){
        cin >> a >> temp[0] >> b >> temp[1] >> c >> temp[2] >> d;
        map[a-1][b-1] = c;
        map[b-1][a-1] = d;
    }
    cin >> a >> temp[0] >> b >> temp[1] >> c >> temp[2] >> d;
    for(int h = 0;h<n;h++){
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            map[j][j] = 0;
            for(int k = 0;k<n;k++){
                map[j][i] = min(map[j][i],map[j][k] + map[k][i]);
            }
        }
    }
    }
    cout << c - (map[a-1][b-1] + map[b-1][a-1] + d) << endl;
    return 0;
}

Measured memory_bytes: 3108
/************************************************
 # @Author:      miniLCT
 # @DateTime:    2019-12-22 19:55:49
 # @Description: You build it.You run it
 # @More: If lots of AC,try BF,dfs,DP
 ***********************************************/
#include <bits/stdc++.h>

using namespace std;
#define eps 1e-8
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
const int maxn = 1e6;
const int INF = 1e9;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9+7;
int main()
{
	int a , b;
	cin >> a >> b ;
	cout << 6 - a -b << endl;
}

/******************************************************
 stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?), set tle
  * do smth instead of nothing and stay organized
*******************************************************/

Measured memory_bytes: 764
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lli long long int
using namespace std;
#define S second
#define F first
#define pb push_back 
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
// map      iterator->first 
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)  
{    int res = 1;    
     x = x % p;
     if (x == 0) return 0;
     while (y > 0)  
     {  if (y & 1)  
        res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
     }  
    return res;  
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	lli t,i,j,n,x,a,b,c,d;
	cin>>a>>b>>c>>d;
    for(j=0;;){
        if(j%2==0){
            c=c-b;
        }
        else{
            a=a-d;
        }
        j++;
        if(a<=0){
            cout<<"No";
            break;
        }
        else if(c<=0){
            cout<<"Yes";
            break;
        }
    }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(void){
    int n;cin>>n;
    vector<ll>V(n);rep(i,n)cin>>V[i];
    sort(V.begin(),V.end());V.push_back(-1);
    int count=0;int ans=0;
    rep(i,n){
        count++;
        if(V[i]!=V[i+1]){ans+=count%2;count=0;}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 25
using namespace std;
int n,a[N],l[N],r[N],used[N];
void dfs(int x,int z){
  if(z==0)cout<<' '<<x;
  if(~l[x])dfs(l[x],z);
  if(z==1)cout<<' '<<x;
  if(~r[x])dfs(r[x],z);
  if(z==2)cout<<' '<<x;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    cin>>l[a[i]]>>r[a[i]];
    if(~l[a[i]])used[l[a[i]]]=1;
    if(~r[a[i]])used[r[a[i]]]=1;
  }
  for(int i=0;i<n;i++)if(!used[i])cout<<"Preorder"<<endl,dfs(i,0),cout<<endl;
  for(int i=0;i<n;i++)if(!used[i])cout<<"Inorder"<<endl,dfs(i,1),cout<<endl;
  for(int i=0;i<n;i++)if(!used[i])cout<<"Postorder"<<endl,dfs(i,2),cout<<endl;
  return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define ios ios_base::sync_with_stdio(0); cin.tie(0);
#define open freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
using namespace std; typedef long long ll; typedef long double ld; mt19937 rnd(time(0));

#define int ll

void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << ' ' << b << ' ' << c << endl;
}

signed main(){
    ios;
    // open;
    ll t = 1;
    // cin >> t;
    cout.precision(16);
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define wh while
#define ve vector
#define mp make_pair
#define tp tuple
#define mt make_tuple
#define pb push_back
#define pof pop_front
#define pob pop_back
#define pf push_front
#define fr front
#define ft first
#define sc second
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / __gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m) - 1;i>=(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) n.begin(), n.end()
#define allr(n) n.rbegin(), n.rend()
#define sp(n) cout << fixed << setprecision(n)
#define pi 3.14159265358979323846
#define inf 1000000007
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

int main() {
  int n, k;
  ci(n, k);
  ve<int> P(n);
  rep(i, n){
    ci(P.at(i));
  }
  sort(all(P));
  int ans = 0;
  rep(i, k){
    ans += P.at(i);
  }
  co(ans);
}


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

void print(vector<  int > &v){
	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
	}
	cout<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //write your code here
		int n, w;
		cin>> n>> w;
		int size =0;
		vector<vector<int > > v(n, vector<int >(2,0));
		rep(i,n){
			cin>> v[i][0]>> v[i][1];
			size+=v[i][1];
		}
		vector<vector<long long int> > dp(n+1, vector<long long int>(size+1, INT_MAX) );
		dp[0][0] = 0;
		rep(i,n){
			rep(j, size+1){
				dp[i+1][j]= min(dp[i+1][j], dp[i][j]);
				if(j-v[i][1]>=0){
					dp[i+1][j]= min(dp[i+1][j], dp[i][j-v[i][1]]+ v[i][0]);
				}
			}
		}
		int ans=0;
		rep(i,size+1){
			if(dp[n][i]<=w){
				ans= i;
			}
		}
		cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	string s, st;
	cin >> s;
	cin  >> s;
	cin >> st;
	cout << "A" << s[0] << "C" << endl;
	return 0;
}


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

using namespace std;

constexpr size_t MAX_N = 100009;
int N, K;
long long H[MAX_N];
long long memo[MAX_N];

long long cost(int i) {
  if (i == N-1) return 0;
  if (i >= N) return LLONG_MAX;

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

  long long ret = LLONG_MAX;
  for (int j=1; j<=K; j++) {
    if (i+j < N) {
      ret = min(ret, abs(H[i] - H[i+j]) + cost(i+j));
    }
  }

  return memo[i] = ret;
}

int main() {

  cin >> N >> K;
  
  for (int i=0; i<N; i++) {
    memo[i] = -1;
  }

  for (int i=0; i<N; i++) {
    cin >> H[i];
  }

  cout << cost(0) << endl;
  
  return 0;
}


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

double calc_e(const vector<int> &v, const vector<double> r, double r0) {
    double e = 0;
    for (int i = 0, size = v.size(); i < size; i++) {
        e += v[i] * r[i];
    }
    e /= r0;
    return e;
}

int main() {
    int t;
    while (cin >> t) {
        double max_e = 0;
        while (t--) {
            int n, m;
            cin >> n >> m;
            vector<int> v(m);
            vector<double> r(m);
            double r0 = 0;
            for (int i = 0; i < m; i++) {
                cin >> v[i] >> r[i];
                r0 += r[i];
            }
            max_e = max(max_e, calc_e(v, r, r0));
        }
        int p, q;
        cin >> p >> q;
        vector<int> v(q);
        vector<double> r(q);
        double r0 = 0;
        for (int i = 0; i < q; i++) {
            cin >> v[i] >> r[i];
            r0 += r[i];
        }
        if (max_e - calc_e(v, r, r0) > 0.0000001) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
struct Matrix{ 
	int a[2][2] = {{0,0},{0,0}};
	Matrix operator *(const Matrix& other){
		Matrix product;
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
						product.a[i][k] =product.a[i][k] + (ll)a[i][j]*other.a[j][k];
				}
			}
		}
		return product;
	}
};
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 ll n,d;
	 cin>>n>>d;
	 d*=d;
	 int ans = 0;
	 while(n--){
		 ll x,y;
		 cin>>x>>y;
		 x*=x;
		 y*=y;
		 if(x+y<=d)
		 ans++;
	 }
	 cout<<ans<<'\n';
	 return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

int main(){
    int n;
    while(cin >> n && n){
        vector<pair<int,int> > sq;
        int num, dir;
        sq.push_back(make_pair(0,0));
        for(int i=0;i<n-1;i++){
            cin >> num >> dir;
            sq.push_back(make_pair(sq[num].first+dx[dir], sq[num].second+dy[dir]));
        }
        int minx = 1 << 29, maxx = -1;
        int miny = 1 << 29, maxy = -1;
        for(int i=0;i<sq.size();i++){
            minx = min(minx, sq[i].first);
            maxx = max(maxx, sq[i].first);
            miny = min(miny, sq[i].second);
            maxy = max(maxy, sq[i].second);
        }
        cout << maxy - miny + 1 << " " << maxx - minx + 1 << endl;
    }
}

Measured memory_bytes: 0
n = int(input())
p = [0] + list(map(int, input().split()))

cnt = 0
for i in range(1, n):
	if p[i] == i:
		p[i], p[i + 1] = p[i + 1], p[i]
		cnt += 1

if p[n] == n:
	cnt += 1

print(cnt)

Measured memory_bytes: 52908
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var A = NextInt();
		var B = NextInt();
		var S = ReadLine();

		WriteLine(Judge(A, B, S) ? "Yes" : "No");
	}

	static bool Judge(int A, int B, string S) {
		var i = 0;
		foreach (var c in S) {
			if (i < A || i + B >= S.Length) {
				if (c == '-') {
					return false;
				}
			} else if (c != '-') {
				return false;
			}
			i++;
		}
		return true;
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define rrep(i,m,n) for(int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K % 2 == 0){
        print(A - B);
    }else{
        print(B - A);
    }
}


Measured memory_bytes: 256
/*
JOI国のお散歩事情
<問題>
JOI 国には東西に走る 1 本の十分に長い道路がある．JOI 国の王宮が道路沿いにあり，
JOI 国における道路沿いの位置は整数 A で表される．A = 0 のときは王宮の位置を表す．
A > 0 のときは，王宮から東へ A メートル進んだ位置を表す．
A < 0 のときは，王宮から西へ -A メートル進んだ位置を表す．
JOI 国の道路沿いには N 軒の家があり，家には西から順に 1 から N までの番号が付けられている．
JOI 国には N 人の国民がいて，国民には 1 から N までの番号が付けられている．
家 i には国民 i が住んでいる．家 i の位置は
 0 でない偶数 Ai で表される．A1, ..., AN は全て異なる．
JOI 国では，近年国民の運動不足が問題になっている．
国民の健康が気になった JOI 国の王様は，国民全員に散歩をする命令を出した．
王様が命令を出すと，全ての国民は一斉に東向きまたは西向きに歩き始める．
それぞれの国民がどちらの向きに歩き始めるかは，国民ごとに決まっている．
全ての国民は，歩くときは 1 秒あたり 1 メートルの速度で歩く．
JOI 国の国民は皆おしゃべりが大好きである．散歩の途中にほかの国民に出会うと，
その場所で立ち止まって世間話を始めてしまう．
すでに立ち止まっている国民に出会った場合も同様である．一度立ち止まった国民は，再び歩き出すことはない．
JOI 国には Q 人の重要人物がいる．JOI 国の王様は，命令が出されてから T 秒後の，
Q 人の重要人物の位置を把握しておきたい．
命令が出されてから T 秒後の，Q 人の重要人物の位置を求めるプログラムを作成せよ．
<入力>
入力は，1 + N + Q 行からなる．

1 行目には，3 つの整数 N，T，Q (1 ≦ N ≦ 100000 (= 105),0 ≦ T ≦ 10の18乗, 
1 ≦ Q ≦ 1000，1 ≦ Q ≦ N) が空白を区切りとして書かれている．
これは ，JOI 国に家が N 軒あり，王様が命令を出してから T 秒後の，
Q 人の重要人物の位置を把握しておきたいことを表す．
続く N 行のうち i 行目には，2 つの整数 Ai, Di (-1018 ≦ Ai ≦ 1018, Ai は 0 でない偶数, 
1 ≦ Di ≦ 2) が空白を区切りとして書かれている．
Ai は家 i の位置を表す偶数である．すべての i (1 ≦ i ≦ N - 1) について，Ai < Ai+1 を満たす．
Di は命令が出された後に国民 i が歩き始める方向を表す．Di = 1 のときは国民 i は東向きに歩き始める．
Di = 2 のときは国民 i は西向きに歩き始める．
続く Q 行のうち i 行目には，整数 Xi (1 ≦ Xi ≦ N) が書かれている．
これは，i 番目の重要人物が家 Xi に住んでいることを表す．
すべての i (1 ≦ i ≦ Q - 1) について，Xi < Xi+1 を満たす．
与えられる 5 つの入力データのうち，入力 1 では N ≦ 100，T ≦ 10000を満たす．
また，入力 2 では N ≦ 5000 を満たす．また，入力 3 では，
ある整数 M (1 ≦ M ≦ N - 1) があって，すべての i (1 ≦ i ≦ M) について Di = 1，
すべての j (M + 1 ≦ j ≦ N) について Dj = 2 を満たす．
また，入力 1，2，3 では，入力に与えられる整数の絶対値は 1000000000 (= 109) を超えない．
入力 4，5 では，与えられる整数が 32 ビット符号付き整数の範囲に収まらないことに注意せよ．
*/

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
//dat["立ち止まる位置"]
long long dat[100010];
//vec[]
long long vec[100010][2];
int main(void){
	int num,query,i,j,z,zb;
	long long t,tt,za;
	i=0;
	cin>>num>>t>>query;
	vec[0][0]=-3000000000000000000LL;
	vec[0][1]=1;
	for(;i<num;i++){
		cin>>za>>zb;
		vec[i+1][0]=za;
		vec[i+1][1]=zb;
	}
	vec[num+1][0]=3000000000000000000LL;
	vec[num+1][1]=2;
	i=0;
	for(;i<=num;i++)
	{
		if(vec[i][1]==1&&vec[i+1][1]==2)
		{
			tt=(vec[i][0]+vec[i+1][0])/2;
			j=i;
			for(;j>=0;j--){
				if(vec[j][1]==1){
					dat[j]=tt;
				}
				else{
					break;
				}
			}
			j=i+1;
			for(;j<num+2;j++){
				if(vec[j][1]==2)
				{
					dat[j]=tt;
				}
				else{
					break;
				}
			}
		}
	}
	i=0;
	for(;i<query;i++){
		cin>>z;
		if(vec[z][1]==1){
			cout<<(vec[z][0]+t<dat[z]?(vec[z][0]+t):(dat[z]))<<endl;
		}
		else{
			cout<<(vec[z][0]-t<dat[z]?(dat[z]):(vec[z][0]-t))<<endl;
		}
	}
	return 0;
}
/*
#include<queue>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
stack<long long> q1;
stack<long long> q2;
int N=0,Q=0,T=0,D=0;
long long A[100010],syugou[1e9];
int main(void){
		cin>>N>>T>Q;
		for(int i=0;i<N;i++){
			cin>>A[i]>>D[i];
			if(D==1){
				q1.push(A[i]);
			}
			else
			{
				q2.push(A[i]);
			}
			if(q1.empty()==0&&q2.empty()==0)
			{
				if(D[i]==1)
				{
					syugou[i]=q1.top();
					syugou[i-1]=q2.top();
					while
					{
						
					}
				}
			}
		}
		return 0;
}*/


Measured memory_bytes: 5456
#include<bits/stdc++.h>
#define       inf                  1<<30
#define       p5                   600000
#define       p6                   1000007
#define       PI                   acos(-1)
#define       M                    1000000007
#define       sc                   scanf
#define       ss                   second
#define       ff                   first
#define       pf                   printf
#define       scin(x)              sc("%d",&(x))
#define       scin2(x,y)            sc("d",&(x),&(y))
#define       READ(f)              freopen(f, "r", stdin)
#define       WRITE(f)             freopen(f, "w", stdout)
#define       ll                   long long
#define       ull                  unsigned long long
#define       pii                  pair < ll, ll>
#define       pp                  pair < ll, ll>
#define       pq                   priority_queue
#define       pb                   push_back
#define       FastRead             ios_base::sync_with_stdio(0);cin.tie(0)
//ll month[]={31,28,31,30,31,30,31,31,30,31,30,31};
//ll dx[5] = {1, -1, 0, 0 };
//ll dy[5] = {0, 0, 1, -1};
using namespace std;
ll w[p5+3],v[p5+3];
bool check[105][p5+2];
ll grd[105][p5+2];
ll knapsack(ll n,ll k)
{
    if(check[n][k]==1){
        return grd[n][k];
    }
    if(n==0 || k==0)
      return 0;
    else if(w[n-1]<=k){
       ll  x=max(v[n-1]+knapsack(n-1,k-w[n-1]),knapsack(n-1,k));
       check[n][k]=1;
       grd[n][k]=x;
       return x;
    }
    else{
        ll xx=knapsack(n-1,k);
        check[n][k]=1;
       grd[n][k]=xx;
       return xx;
    }

}
int main()
{
    ll i,n,j,k;
    sc("%lld%lld",&n,&k);
    for(i=0; i<n; i++)
    {
        sc("%lld%lld",&w[i],&v[i]);;
    }
    ll aa=knapsack(n,k);
    pf("%lld\n",aa);
    return 0;
}
/*
26 6
26 64
22 85
4 52
18 99
13 39
9 54
*/



Measured memory_bytes: 342272
N,K =map(int,input().split())
result = [0]*(10**5+1)
for i in range(N):
  a,b = map(int,input().split())
  result[a] += b
count = 0
for j in range(len(result)):
  count += result[j]
  if count >= K:
    print(j)
    break


Measured memory_bytes: 5748
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;
use std::cmp;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

trait MaxAssign {
    fn max_assign(&mut self, other: u16);
}

impl MaxAssign for u16 {
    fn max_assign(&mut self, other: u16) {
        *self = cmp::max(*self, other);
    }
}

fn evaluate(n: usize, s: Vec<char>) -> Vec<Vec<Vec<u16>>> {
    let mut dp = vec![vec![vec![0_u16; 3]; n + 1]; n + 1];

    for i in 0..(n - 1) {
        for j in (i + 1)..n {
            if s[i] == s[j] {
                if dp[i][j][0] == 0 {
                    dp[i + 1][j + 1][0].max_assign(1);
                    dp[i + 1][j + 1][1] = (j - i) as u16;
                    {
                        let x = dp[i + 1][j + 1][0];
                        dp[i + 1][j + 1][2].max_assign(x);
                    }
                } else {
                    if dp[i][j][1] > 1 {
                        {
                            let x = dp[i][j][0] + 1;
                            dp[i + 1][j + 1][0].max_assign(x);
                        }
                        dp[i + 1][j + 1][1] = dp[i][j][1] - 1;
                        {
                            let x = dp[i + 1][j + 1][0];
                            dp[i + 1][j + 1][2].max_assign(x);
                        }
                    } else if dp[i][j][1] == 1 {
                        dp[i + 1][j + 1][2] = cmp::max(dp[i][j][2], dp[i][j][0]);
                    }
                }
            }
            {
                let x = dp[i + 1][j][2];
                dp[i + 1][j + 1][2].max_assign(x);
            }
            {
                let x = dp[i][j + 1][2];
                dp[i + 1][j + 1][2].max_assign(x);
            }
        }
    }
    dp
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n: usize = iter.parse();
    let s: Vec<char> = iter.next().unwrap().chars().collect();

    println!("{}", evaluate(n, s)[n - 1][n][2]);
}

Measured memory_bytes: 878844
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

stot = dict()
ttos = dict()

s = lc()
t = lc()

ans = True

for si,ti in zip(s,t):
    if not si in stot.keys():
        stot.update({si: ti})
    elif stot[si] != ti:
        ans = False
        break
        
    if not ti in ttos.keys():
        ttos.update({ti: si})
    elif ttos[ti] != si:
        ans = False
        break
    
print('Yes') if ans else print('No')

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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        xu: [(f64, String); n],
    }
    let mut sum: f64 = 0.0;
    for v in xu {
        if v.1 == "JPY".to_string() {
            sum += v.0;
        } else {
            sum += v.0 * 380000.0;
        }
    }
    println!("{}", sum);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string n;
	cin>>n;
	long long int i,a=0,b=0;
	for(i=0;i<n.size();++i)
	{
		if(i%2==0) 
		{
			if(n[i]=='0')++b;
			else++a;
		}
		else
		{
			if(n[i]=='1')++b;
			else++a;
		} 
    }
	if(a<b)
	{
		cout<<a;
	}
	else
	{
		cout<<b; 
	}
    return 0;	
}

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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

typedef long long ll;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("F.in", "r", stdin);
	freopen ("F.out", "w", stdout);
#endif
}

const int N = 200100;

const ll inf = 0x3f3f3f3f3f3f3f3f;

#define mid ((l + r) >> 1)
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r

template<int Maxn>
struct Segment_Tree {

	ll minv[Maxn], tag[Maxn];

	inline void add(int o, ll uv) {
		minv[o] += uv; tag[o] += uv;
	}

	inline void push_down(int o) {
		if (tag[o]) 
			add(o << 1, tag[o]), add(o << 1 | 1, tag[o]), tag[o] = 0;
	}

	inline void push_up(int o) {
		minv[o] = min(minv[o << 1], minv[o << 1 | 1]);
	}

	void Update(int o, int l, int r, int up, ll uv) {
		if (l == r) { minv[o] = uv; return; } push_down(o);
		up <= mid ? Update(lson, up, uv) : Update(rson, up, uv); push_up(o);
	}

	void Update(int o, int l, int r, int ul, int ur, ll uv) {
		if (ul <= l && r <= ur) { add(o, uv); return; } push_down(o);
		if (ul <= mid) Update(lson, ul, ur, uv);
		if (ur > mid) Update(rson, ul, ur, uv); push_up(o);
	}

	ll Query(int o, int l, int r, int ql, int qr) {
		if (ql <= l && r <= qr) return minv[o];
		push_down(o);
		if (qr <= mid) return Query(lson, ql, qr);
		if (ql > mid) return Query(rson, ql, qr);
		return min(Query(lson, ql, qr), Query(rson, ql, qr));
	}

};

Segment_Tree<N << 2> TL, TR;

#define root 1, 1, n

int n, q, x[N]; ll f[N], g[N], ans = inf;

inline void Modify(int pos, ll uv) {
	TL.Update(root, pos, uv - pos); TR.Update(root, pos, uv + pos);
}

int main () {

	File();

	n = read(); q = read(); 
	x[0] = read(); int p = read();
	For (i, 1, n) Modify(i, abs(p - i));

	For (i, 1, q) {
		x[i] = read();
		ll tmp = min(TL.Query(root, 1, x[i]) + x[i], TR.Query(root, x[i], n) - x[i]);
		TL.Update(root, 1, n, abs(x[i - 1] - x[i])); 
		TR.Update(root, 1, n, abs(x[i - 1] - x[i])); Modify(x[i - 1], tmp);
	}

	ll ans = inf;
	For (i, 1, n)
		chkmin(ans, TL.Query(root, i, i) + i);
	printf ("%lld\n", ans);

	return 0;

}

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

int main() {
  
  
  int max = 0;
 
  int N; 
  cin >> N;
  vector<string> n(N);
    
  for(int i = 0; i < N; i++){
  	cin >> n.at(i);
  }  
  
    
  
  int M;
  cin >> M;
  vector<string> m(M);
  string tmp;
  
  for(int i = 0; i < M; i++){
  	cin >> m.at(i);
  }
  
  
  
  for(int i = 0; i < N; i++){
    int count = 0;
    tmp = n.at(i);
    
    for(int t = 0;  t < N; t++){
    	if(tmp == n.at(t)){
        	count++; } 
           }
           
    for(int t = 0; t < M; t++){
    	if(tmp == m.at(t)){
        	count--; }
           }
    
    if(max < count){
    	max = count; }
    
  }
  
  
  cout << max;
  
  
      
}
  

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
long soto(const void *a,const void *b){
  return *(long*)a - *(long*)b;
}

int main(){
  int n=0,k=0,min=-1;
  long h[100000] = {};
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%ld",&h[i]);
  }
  qsort(h,n,sizeof(long),soto);
  for(int i=0;i<=n-k;i++){
    if((h[i+k-1]-h[i]<min)||(min==-1)){
      min = h[i+k-1] - h[i];
    }
  }
  printf("%ld",min);
  return 0;
}


Measured memory_bytes: 1788
#include <vector>
#include <cstdio>
#include <stack>
#include <string>
#define help cout<<"I don't want to die!"<<endl;
using namespace std;
/*
void print(int a){
    cout<<a<<endl;
}
void print(int a,string b){
	cout<<a<<b;
}
void print(vector<int> a){
    for (int i = 0;i<a.size();++i){
        print(a[i]," ");
    }
    cout<<endl;
}*/
int main(){
    long long marxism = -10000000000000;
    vector<stack<int> > ms;//monotonic stack;
    vector<int> dis;
    vector<long long> cf;//distance between shops,0:0->1;chafenshuzu
    vector< vector<int> > tickets;
    int shop,tic;
    scanf("%d %d",&shop,&tic);
    /*initialization*/
    cf.assign(shop-1,0);
    tickets.assign(tic,vector<int>());
    ms.assign(tic,stack<int>());
    dis.reserve(shop);
    /*done*/
    for (register int i = 1;i<shop;++i){
        int temp;scanf("%d",&temp);
        dis.push_back(-temp);
    }
    //convert the distance into "chafen" form;
    for (register int i = 0;i<shop;++i){
        for (register int j = 0;j<tic;++j){
            int temp;scanf("%d",&temp);
            tickets[j].push_back(temp);
        }
    }
    //get the tickets'value
    //tickets[i][j]:the value of ticket i in the shop j
    for (register int i = shop-1;i>=0;--i){
	long long result = 0;
        //enumerate start point from tail to head;
        for (register int j = 0;j<ms.size();++j){
            //process the "chafenshuzu" of each ticket.
            int cur = tickets[j][i],prev = 0;//prev is the previous shop,used to determine how large to shrink in the next shop;
            while (!ms[j].empty()){
                if (cur>tickets[j][ms[j].top()]){//the one we have is greater than the top of the stack;
                    cf[ms[j].top()-1] -=(tickets[j][ms[j].top()]-prev);
                    prev = tickets[j][ms[j].top()];
                    ms[j].pop();
                }
                else{
                    cf[ms[j].top()-1] -=(cur-prev);
                    break;
                }
            }
	    result += cur;
	    if (i) cf[i-1] +=cur;
            ms[j].push(i);
        }
	//update the 'chafen' completed;
        marxism = max(marxism,result);
        for (register int j = i;j<shop-1;++j){
            result +=  dis[j];
            result +=  cf[j];
            marxism = max(marxism,result);
        }
    }
    printf("%lld",marxism);
}


Measured memory_bytes: 6016