akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


struct MaxMonoid {
  using T = lint;
  static T op(const T& lhs, const T& rhs) { return max(lhs, rhs); }
  static constexpr T e() { return 0; }
};

template<class Monoid> struct SegmentTree {
  using M = Monoid;
  using T = typename M::T;

  const int n;

  SegmentTree(int n, const T& a = M::e()) : n(n), val(2 * n, a) {
    build();
  }

  template<class Itr> SegmentTree(Itr first, Itr last) :
    n(distance(first, last)), val(2 * n, M::e()) {
    copy(first, last, next(begin(val), n));
    build();
  }

  T& operator[](int i) {
    assert(0 <= i and i < n);
    return val[i + n];
  }

  void build() {
    for (int i = n - 1; i > 0; --i) {
      val[i] = M::op(val[2 * i], val[2 * i + 1]);
    }
  }

  T get(int l, int r) const {
    l = max(l, 0), r = min(r, n);
    T resl = M::e(), resr = M::e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = M::op(resl, val[l++]);
      if (r & 1) resr = M::op(val[--r], resr);
    }
    return M::op(resl, resr);
  }

  void set(int i, const T& a) {
    assert(0 <= i and i < n);
    for (val[i += n] = a, i >>= 1; i > 0; i >>= 1) {
      val[i] = M::op(val[2 * i], val[2 * i + 1]);
    }
  }

private:
  V<T> val;
};

using ST = SegmentTree<MaxMonoid>;

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  V<> h(n); for (int i = 0; i < n; ++i) cin >> h[i], --h[i];
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  ST dp(n);
  for (int i = 0; i < n; ++i) {
    dp.set(h[i], dp.get(0, h[i]) + a[i]);
  }
  cout << dp.get(0, n) << '\n';
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  string s;
  cin >> s;
  ll ans = 0;
  ll key = 0;
  rep(i,1<<s.size()-1){
    key = 0;
    ans += s[s.size()-1]-48;
    rep1(j,s.size()){
      if(i>>(j-1)&1){
        //cout << 'a' << endl;
        key = 0;
        //cout << j << " " <<  s[s.size()-1-j] << " " << pow(10,key) << endl;
        ans += s[s.size()-1-j]-48;
      }
      else{
        key++;
        //cout << 'b' << endl;
        //cout << j << " " <<  s[s.size()-1-j] << " " << pow(10,key) << endl;
        ans += (s[s.size()-1-j]-48)*pow(10,key);
      }
      //cout << ans << endl;
    }
  }
  cout << ans << endl;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int r;
    cin >> r;

    if (r < 1200)
        cout << "ABC" << endl;
    else if (r < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
ll n, m;
ll xx[61];
ll dap;
ll gap;
pair<ll, ll> b[61];
pair<ll, ll> a[61];
ll parse[61][8];

vector < vector<pair<ll,ll>>> vt;
ll de[61];
ll dfs(ll here,ll par, ll en,ll ch2) {
	if (here == en)return 1;
	for (ll i = 0; i < vt[here].size(); i++) {
		ll next = vt[here][i].first;
		if (next == par)continue;
		if (dfs(next, here, en,ch2)) {
			xx[vt[here][i].second] |= ((ll)1<<ch2);
			return 1;
		}
	}
	return 0;
}
void func(ll here, ll ch,ll update) {
	if (here == m) {
		ll sum = 0;
		ll oo = 0;
		for (ll i = 0; i < n-1; i++) {
			if (ch & xx[i])oo++;
		}
		oo = (n - 1 - oo);
		sum = ((ll)1 << oo);
		if (update % 2)gap -= sum;
		else gap += sum;
		return;
	}
	func(here+1 , ch + ((ll)1 << here), update+1);
	func(here+1, ch, update);
}
int main()
{
	scanf("%lld", &n);
	vt.resize(n + 1);
	for (ll i = 0; i < n - 1; i++) {
		ll q, w;
		scanf("%lld %lld", &q, &w);
		b[i] = { q,w };
		vt[q].push_back({ w ,i});
		vt[w].push_back({ q ,i});
	}
	scanf("%lld", &m);
	for (ll i = 0; i < m; i++) {
		scanf("%lld %lld", &a[i].first, &a[i].second);
		dfs(a[i].first, -1, a[i].second, i);
	}
	func(0, 0, 0);
	printf("%lld", gap);
}

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

int main(){
  int n;
  cin>>n;
  int d=n%10;
  n/=10;
  int c=n%10;
  n/=10;
  int b=n%10;
  n/=10;
  int a=n;
  vector<int> vec={b,c,d};
  
  
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
    bitset<3> s(tmp);
    int sum=a;
    vector<string> vecstr(3);
    for(int i=0;i<3;i++){
      if(s.test(i)){
        sum+=vec.at(i);
        vecstr.at(i)="+";
      }
      else{
        sum-=vec.at(i);
        vecstr.at(i)="-";
      }
    }
    if(sum==7){
      cout<<a<<vecstr.at(0)<<b<<vecstr.at(1)<<c<<vecstr.at(2)<<d<<"="<<7<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(void)
{
    ll a, b, c, d;
    ll x[4];    

    cin >> a >> b >> c >> d;
    x[0] = a * c;
    x[1] = a * d;
    x[2] = b * c;
    x[3] = b * d;
    sort(x, x + 4);
    cout << x[3] << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {

			double a = Double.parseDouble(line);
			double[] prog = new double[10];
			double sum = 0;

			for (int i = 0; i < 10; i++) {
				if (i == 0) {
					prog[i] = a;
				} else if ((i % 2) == 1) {
					prog[i] = prog[i - 1] * 2;
				} else {
					prog[i] = prog[i - 1] / 3;
				}
			}
			for (int i = 0; i < 10; i++) {
				sum += prog[i];
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 16920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  int l, r, d;
  cin >> l >> r >> d;
  int a = 0;
  for(int i = 0; i <= r ; i += d) {
    if(i < l) continue;
    a++;
  }
  cout << a << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


int main(){
	int a,b;
	scanf("%d %d",&a, &b);
	int tmp = a;
	for(int i=1;i<=b;i*=10) tmp*=10;
	tmp += b;

	for(int i=1;i<=500;i++){
		if(tmp == i*i){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");

	return 0;
}


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

using namespace std;
using ll = long long;

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

  int n;
  ll h;
  cin >> n >> h;
  vector<ll> a(n);
  vector<ll> b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];

  ll ma = *max_element(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<ll>());

  ll ans = h / ma + ll(h % ma > 0);
  for (int i = 0; i < n; i++) {
    h -= b[i];
    if (h <= 0) {
      ans = min(ans, 1ll * i + 1);
      break;
    } else {
      ans = min(ans, i + 1 + h / ma + ll(h % ma > 0));
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4760
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long ans = k;
        for (int i = 0 ; i < n - 1 ; i++) {
            ans *= (long)  (k - 1);
            if (ans > 2147483647) {
                System.out.println(2147483647);
                return;
            }
        }
        System.out.println(ans);

    }

}

Measured memory_bytes: 22740
#include <cstdio>
#include <cmath>
using namespace std;

int a, b;
int s[6] = {1, 10, 100, 1000, 10000, 100000};

inline int work(int n) {
	int k = 0;
	while (n > 0) {
		n /= 10;
		k++;
	}
	return k;
}

inline bool check(int n) {
	return sqrt(n) == (int)sqrt(n);
}

int main() {
	scanf("%d %d", &a, &b);
	if (check(a * s[work(b)] + b)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARINGS
#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<map>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<fstream>
#include<map>
#include<unordered_map>
using namespace std;
typedef int me;
typedef long long ll;
typedef unsigned long long ull;
#define andrew  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define sz(v)(int)(v.size())
#define all(v) v.begin(),v.end()
#define PI 3.1415926535
#define sin(i) (long double)sin(i*PI/180.0);
#define OO 1e18;
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }
void the_end() {
#ifndef ONLINE_JUDGE;
    system("pause");
#endif
}
int dy8[] = { 0,0,1,-1,1,-1,-1,1 };
int dx8[] = { 1,-1,0,0,1,-1,1,-1 };
int id8[] = { 0, 1,2,3,4, 5,6, 7 };
// you can be specialist 
// soon will be (Cyain)
ll n;
vector<pair<ll, ll>>v;
ll mm[101][100001];
ll solve(ll i,ll k)
{
    if (i == n)
    {
        if (k == 0)
            return 0;

        return 1e10;
    }
    if (mm[i][k] != -1)
        return mm[i][k];
    mm[i][k] = solve(i + 1, k);
    if (k - v[i].second >= 0)
        mm[i][k] = min(mm[i][k], solve(i + 1, k - v[i].second) + v[i].first);

    return mm[i][k];
}
int main()
{
    andrew;
    for (int i = 0; i < 101; i++)
        for (int j = 0; j < 100001;j++)
            mm[i][j] = -1;
    int w;
    cin >> n >> w;
    v.resize(n);
    for (int i = 0; i < n; i++)
        cin >> v[i].first >> v[i].second;


    ll sum = 0;
    for (auto it : v)
        sum += it.second;
    ll ans = 0;
    for (int i = 0; i <= sum; i++)
    {
       ll b = solve(0, i);
       if (b <= w)
           ans = i;
    }
    cout << ans << endl;

    the_end();
}

Measured memory_bytes: 79360
#include <cmath>
#include <iostream>
using namespace std;
int x, m = 0;
int main() {
  cin >> x;
  for (int i = 1; i <= x; i++) {
    for (int j = 2; j <= 1000; j++) {
      int p = pow(i, j);
      if (p > x) {
        break;
      }
      if (m < p) {
        m = p;
      }
    }
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
A[10000],B[10000];z(int*a,int*b){return*b-*a;}
main(n,i,j){for(;scanf("%d",&n),n;puts(i>n?"No":"Yes")){
for(i=0;i<n;i++)scanf("%d",A+i);
for(i=0;i<n;i++)scanf("%d",B+i);
for(i=qsort(A,n,4,z);i<n;i++){for(j=0;j<n;j++)if(B[j])A[i]--,B[j]--;if(A[i])i=n;}
}exit(0);}

Measured memory_bytes: 732
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int x, t;
	cin >> x >> t;
	if(x>t)	cout << (x - t) << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<climits>
#include<algorithm>
#include<utility>
#define int long long
using namespace std;
int x;
signed main(){
	scanf("%lld", &x);
	if(x>=400 && x<=599) printf("8");
	else if(x>=600 && x<=799) printf("7");
	else if(x>=800 && x<=999) printf("6");
	else if(x>=1000 && x<=1199) printf("5");
	else if(x>=1200 && x<=1399) printf("4");
	else if(x>=1400 && x<=1599) printf("3");
	else if(x>=1600 && x<=1799) printf("2");
	else if(x>=1800 && x<=1999) printf("1");
	return 0;
}

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

int main()
{
	int n, x, i, j, k, s;
	
	while(1){
		cin >> n >> x;
		if(n == 0 && x == 0){
			break;
		}
		
		s = 0;
		for(i = 1; i <= n - 2; i++){
			for(j = i + 1; j <= n - 1; j++){
				for(k = j + 1; k <= n; k++){
					if(i + j + k == x){
						s++;
					}
				}
			}
		}
		cout << s << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	int check_word[26],check_num[10];
	for(int i = 0; i <= 25; i++)check_word[i] = 0;
	for(int i = 0; i <= 9; i++)check_num[i] = 0;

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

	char buf[N+1];
	scanf("%s",buf);

	for(int i = 0; i < N; i += 2){
		check_word[buf[i]-'a']++;
	}

	for(int i = 0; i <= 25; i++){
		check_num[check_word[i]]++;
	}

	int ans = 0;

	if(check_num[1] > 0)ans = 2*check_num[1]-1;

	for(int i = 2; i <= 9; i++){
		if(check_num[i] > 0){
			if(ans > 0){
				ans++;
			}

			if(check_num[i] == 1){
				ans += 3;
			}else{
				ans += 2*check_num[i]+3;
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 3152
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	int c[3][3];
	rep(i,0,3)
		rep(j,0,3)
			cin >> c[i][j];

	int a1,a2,a3,b1,b2,b3;

	rep(i,0,101){
		a1 = i;
		rep(j,0,101){
			a2 = j;
			rep(k,0,101){
				a3 = k;
				b1 = c[0][0] - a1;
				b2 = c[0][1] - a1;
				b3 = c[0][2] - a1;
				
				if( c[1][0]-b1 == a2 && c[1][1]-b2 == a2 && c[1][2]-b3 == a2 && c[2][0]-b1 == a3 && c[2][1]-b2 == a3 && c[2][2]-b3 == a3){
					Yes;
					ret 0;
				}
			}
		}
	}
	No;
	ret 0;
}

Measured memory_bytes: 256
n = int(input())
A =list(map(int, input().split()))
cnt = 0
B = []
for i in range(n):
    if 1 <= A[i] <= 399:
        B.append(0)
    elif 400 <= A[i] <= 799:
        B.append(1)
    elif 800 <= A[i] <= 1199:
        B.append(2)
    elif 1200 <= A[i] <= 1599:
        B.append(3)
    elif 1600 <= A[i] <= 1999:
        B.append(4)
    elif 2000 <= A[i] <= 2399:
        B.append(5)
    elif 2400 <= A[i] <= 2799:
        B.append(6)
    elif 2800 <= A[i] <= 3199:
        B.append(7)
    else:
        #A[i] = 8
        cnt += 1
#ans =len(set(A))+cnt-1
if len(B) == 0 and cnt != 0:
    print(1, cnt)
else:
    print(len(set(B)), len(set(B))+cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N;
    cin >> N;
    vector<char> a(N);
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
    }
    bool check = true;

    for (ll i = 0; i < N; i++) {
        if(a[i] == '2'){
            check = false;
            break;
        }
    }

    ll f;
    if(check){
        f = 0;
        for (ll i = 0; i < N; i++) {
            if((N - 1) == ( i | (N - i - 1) )){
                if(a[i] == '3'){
                    f++;
                }
            }
        }

        if(f % 2 == 0){
            printf("0\n");
            return 0;
        }
        else{
            printf("2\n");
            return 0;
        }
    }

    f = 0;
    for (ll i = 0; i < N; i++) {
        if((N - 1) == ( i | (N - i - 1) )){
            f += a[i] - '0';
        }
    }
    if(f % 2 == 0){
        printf("0\n");
    }
    else{
        printf("1\n");
    }

}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  using pill = pair<int, ll>;
  vector<pill> vp(n);
  for (int i = 0; i < n; i++)
    cin >> vp[i].first >> vp[i].second;
  sort(vp.begin(), vp.end(),
       [](const pill &l, const pill &r) { return l.second > r.second; });
  map<int, vector<ll>> s;
  map<int, ll> mp;
  for (int i = 0; i < n; i++) {
    mp[vp[i].first] = max(mp[vp[i].first], vp[i].second);
  }
  ll ans = 0, score = 0;
  vll v;
  for (int i = 0; i < k; i++) {
    s[vp[i].first].push_back(vp[i].second);
    score += vp[i].second;
  }
  for (auto it : s) {
    sort(it.second.begin(), it.second.end());
    for (int i = 0; i < it.second.size() - 1; i++)
      v.push_back(it.second[i]);
  }
  sort(v.begin(), v.end());
  ans = score + s.size() * s.size();
  multiset<ll> get;
  for (auto &it : mp) {
    if (s.find(it.first) == s.end()) {
      get.insert(-it.second);
    }
  }
  int vid = 0;
  while (get.size() && vid < v.size()) {
    score -= v[vid++];
    score += -*get.begin();
    s[-vid].push_back(-*get.begin());
    get.erase(get.begin());
    ans = max(ans, (ll)(score + s.size() * s.size()));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n; cin >> n;
	long long a[3], b[3];
	for(int i = 0; i < 3; i++) cin >> a[i];
	for(int i = 0; i < 3; i++) cin >> b[i];
	long long ans = n;
	auto move_id = [&](int id, long long corn){
		if(a[id] > b[id]){
			return (corn / b[id]) * a[id] + (corn % b[id]);
		} else {
			return (corn / a[id]) * b[id] + (corn % a[id]);
		}
	};
	vector<int> amove, bmove;
	for(int i = 0; i < 3; i++) 
		if(a[i] < b[i]) amove.push_back(i);
		else bmove.push_back(i);
	if(amove.empty() || bmove.empty()){
		for(int i = 0; i <= n; i++){
			for(int j = 0; j + i <= n; j++){
				ans = max(ans, move_id(0, i) + move_id(1, j) + move_id(2, n - i - j));
			}
		}
	} else {
		long long mid = n;
		if(amove.size() == 1){
			int ina = amove[0];
			mid = (mid / a[ina]) * b[ina] + (mid % a[ina]);
		} else {
			for(int i = 0; i <= n; i++) for(int j = 0; j + i <= n; j++) mid = max(mid, + n - i - j + move_id(amove[0], i) + move_id(amove[1], j));
		}
		if(bmove.size() == 1){
			int inb = bmove[0];
			ans = (mid / b[inb]) * a[inb] + (mid % b[inb]);
		} else {
			int b0 = bmove[0], b1 = bmove[1];
			for(int i = 0; i <= mid; i++){
				ans = max(ans, move_id(b0, i) + move_id(b1, mid - i));
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

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

    int N = scanner.nextInt();
    HashSet<Integer> set = new HashSet<>();
    for (int i = 1; i <= N; i++) set.add(i);

    List<String> list = build(set, "");
    Collections.sort(list);

    StringBuilder p = new StringBuilder();
    for (int i = 0; i < N; i++) p.append(scanner.nextInt());
    StringBuilder q = new StringBuilder();
    for (int i = 0; i < N; i++) q.append(scanner.nextInt());

    System.out.println(Math.abs(list.indexOf(p.toString()) - list.indexOf(q.toString())));
  }

  private static List<String> build(Set<Integer> remaining, String str) {
    if (remaining.isEmpty()) {
      List<String> res = new ArrayList<>();
      res.add(str);
      return res;
    }
    List<String> res = new ArrayList<>();
    for (int n : remaining) {
      Set<Integer> s = new HashSet<>(remaining);
      s.remove(n);
      for (String t : build(s, str)) {
        res.add(t + n);
      }
    }
    return res;
  }
}


Measured memory_bytes: 62556
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  a = InputLine.to_i
  puts (a + a ** 2 + a ** 3).to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 14248
#include<iostream>
using namespace std;
int n,m,w[100];
main()
{
	while(cin>>m>>n,n)
	{
		for(int i=0;i<n;i++)cin>>w[i];
		int l=0,r=1500001;
		while(r-l>1)
		{
			int W=(r+l)/2;
			int i=0;
			for(int j=0;j<m;j++)
			{
				int sum=0;
				while(i<n&&sum+w[i]<=W)sum+=w[i++];
			}
			if(i<n)l=W;
			else r=W;
		}
		cout<<r<<endl;
	}
}



Measured memory_bytes: 3072
N = int(input())
S = list(input())
Q = int(input())

'''
'init(a)': 配列aで初期化。O(N)
'update(k,x)': a[k]をxに変更 O(logN)
'query(p,q)': [p,q)について "segfunc" したものを返す O(logN)
'ide_ele' : 単位元。
'''

#####segfunc######


def segfunc(x, y):
    return x | y


def init(init_val):
    # set_val
    for i in range(N):
        seg[i+num-1] = init_val[i]
    # built
    for i in range(num-2, -1, -1):
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])


def update(k, x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1], seg[k*2+2])


def query(p, q):
    if q <= p:
        return ide_ele
    p += num-1
    q += num-2
    res = ide_ele
    while q-p > 1:
        if p & 1 == 0:
            res = segfunc(res, seg[p])
        if q & 1 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(segfunc(res, seg[p]), seg[q])
    return res


#####単位元######
ide_ele = 0

# num:n以上の最小の2のべき乗
num = 2**(N-1).bit_length()
seg = [ide_ele]*2*num


init_val = []
for s in S:
    init_val.append(1 << (ord(s)-ord('a')))
init(init_val)

for _ in range(Q):
    t, s, u = input().split()
    if t == '1':
        update(int(s)-1, 1 << (ord(u)-ord('a')))
    else:
        print(bin(query(int(s)-1, int(u))).count('1'))


Measured memory_bytes: 108456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws IOException {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");

        String s1 = arr01[0];
        Integer a = Integer.valueOf(s1);
        String s2 = arr01[1];
        Integer b = Integer.valueOf(s2);

        Boolean chkflg = true;
        int i = 0;
        while (chkflg) {

            if (a + (i - 1) * (a - 1) >= b) {
                chkflg = false;

            } else {
                i += 1;
            }

        }
        System.out.println(i);

    }

}

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

int main(){
	long long n,i,q;
	long long cnt = 0;
	cin >> n;
	long long a[100000];
	for (long long i = 0; i < n; i++){
		cin >> a[i];
	}
	if (a[0]>1){
		cnt+=a[0]-1;
	}
	i = 1;
	q = 1;
	
	while (i<n){
		if (a[i] >(q+1)){
			cnt += ((a[i] - 1) / (q+1));
			a[i] = 1;
		}
		else if((q+1)==a[i]){
			q = a[i];
		}
		i++;
	}
	//cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int h, w, k;
    cin >> h >> w >> k;
    if (h < w) swap(h, w);
    cout << (k + h - 1) / h << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
string s[20],si[20];
int r[20];
bool visr[20],visc[20];
void dfsc(int x,bool fl)
{
	if (x==m)
	{
		cout <<"YES";
		exit(0);
	}
	if (visc[x])
	{
		dfsc(x+1,fl);
		return;
	}
	visc[x]=1;
	for (int i=0;i<m;i++)
	{
		if (visc[i]) continue;
		bool jum=0;
		for (int j=0;j<n;j++) if (s[j][x]!=s[r[j]][i]) jum=1;
		if (jum) continue;
		visc[i]=1;
		dfsc(x+1,fl);
		visc[i]=0;
	}
	if (fl)
	{
		bool jum=0;
		for (int j=0;j<n;j++) if (s[j][x]!=s[r[j]][x]) jum=1;
		if (!jum) dfsc(x+1,0);
	}
	visc[x]=0;
}
void dfsr(int x,bool fl)
{
	if (x==n)
	{
		dfsc(0,m%2!=0);
		return;
	}
	if (visr[x])
	{
		dfsr(x+1,fl);
		return;
	}
	visr[x]=1;
	for (int i=0;i<n;i++)
	{
		if (visr[i] || si[x]!=si[i]) continue;
		r[x]=i,r[i]=x;
		visr[i]=1;
		dfsr(x+1,fl);
		visr[i]=0;
	}
	if (fl)
	{
		r[x]=x;
		dfsr(x+1,0);
	}
	visr[x]=0;
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++)
	{
		cin >>s[i];
		si[i]=s[i];
		sort(si[i].begin(),si[i].end());
	}
	dfsr(0,n%2!=0);
	cout <<"NO";
	return 0;
} 

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

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const ll INF = LONG_MAX;

ll solve(const ll R, const ll S, const ll P, const vector<char> as) {
    int len = (int) as.size();
    vector<vector<ll> > dp(len, vector<ll>(3, 0)); // 0: r, 1: s, 2: p
    ll point;
    if (as[0] == 'r') {
        point = P;
        dp[0][0] = 0;
        dp[0][1] = 0;
        dp[0][2] = point;
    } else if (as[0] == 's') {
        point = R;
        dp[0][0] = point;
        dp[0][1] = 0;
        dp[0][2] = 0;
    } else {
        point = S;
        dp[0][0] = 0;
        dp[0][1] = point;
        dp[0][2] = 0;
    }

    for (int i = 1; i < len; i++) {
        ll point;
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]);
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]);

        if (as[i] == 'r') {
            point = P;
            dp[i][2] += point;
        } else if (as[i] == 's') {
            point = R;
            dp[i][0] += point;
        } else {
            point = S;
            dp[i][1] += point;
        }
    }

    return max(max(dp[len - 1][0], dp[len - 1][1]), dp[len - 1][2]);
}

int main(void) {
    ll N, K;
    cin >> N >> K;

    ll R, S, P;
    cin >> R >> S >> P;

    string T;
    cin >> T;

    vector<vector<char> > ass(K);
    for (int i = 0; i < N; i++) {
        ass[i % K].push_back(T[i]);
    }

    ll ans = 0;
    for (int i = 0; i < K; i++) {
        // for (int j = 0; j < (int) ass[i].size(); j++) {
        //     cout << ass[i][j] << " ";
        // }
        // cout << endl;
        ans += solve(R, S, P, ass[i]);
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
  int S;
  cin>>S;
  int A[1000010];
  int n=1;
  A[1]=S;
  while(n<1000001){
    n++;
    if (A[n-1]%2==0){
      A[n]=A[n-1]/2;
    }
    else {
      A[n]=A[n-1]*3+1;
    }
    
    for(int i=1;i<n;i++){
      if(A[n]==A[i]){
        cout<<n<<endl;
        return 0;
      }
    }
  }
  return 0;
}

  
  
  

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
 
    int n = sc.nextInt();
    int m = sc.nextInt();
    int k = sc.nextInt();

    int ans = 0;
    if(n + m >= k){
      ans = k + m;
    }else{
      ans = n + 2 * m + 1;
    }

    System.out.println(ans);

 
  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if( (a * 100 + b * 10 + c ) % 4 == 0 ) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import exit
import queue
V,E = [int(n) for n in input().split()]
ans = []

# N = int(input())
graph = [[] for _ in range(V)]
indeg = [0]*V
yet = [True]*V
def bfs(s):
    q = queue.Queue()
    q.put(s)
    while(not q.empty()):
        u = q.get()
        ans.append(u)
        yet[u]=False
        for v in graph[u]:
            indeg[v]-=1
            if(indeg[v]==0):
                q.put(v)

for i in range(E):
    s, t = [int(n) for n in input().split()]
    graph[s].append(t)
    indeg[t]+=1
for i in range(V):
    if(indeg[i]==0 and yet[i]):
        bfs(i)
for a in ans:
    print(a)
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()



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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll N;
vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

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

  ll n;
  cin >> n;
  map<string, int> m;
  rep(i, n) {
    string s;
    cin >> s;
    m[s]++;
  }

  int maxv = 0;

  for(auto a: m) maxv=max(maxv, a.second);
  for(auto it = m.begin(); it != m.end(); it++) {
    if (it->second == maxv) {
      cout << it->first << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 23936
import heapq as hq

N = int(input())
A = [int(a) for a in input().split()]

h = []
for i in range(N):
    hq.heappush(h, (A[i], i+1))

for i in range(N):
    A[i] = hq.heappop(h)[1]

print(*A)


Measured memory_bytes: 66604
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    bool res = false;

    for (int i = 0; i <= 7; i++) {
        int j = 7 - i;
        string pre = s.substr(0, i);
        string suf = s.substr(n-j, j);
        string cp = pre + suf;
        if (cp == "keyence") res = true;
    }

    if (res) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstring>
using namespace std;
#define MAX_N 1000000
#define MAX_C 32
bool dp[MAX_N * 2];
bool prime[MAX_N]; int n, m, a[MAX_C];
int main() {
	for (int i = 2; i < MAX_N; i++) { prime[i] = true; }
	for (int i = 2; i*i < MAX_N; i++) {
		for (int j = i*i; j < MAX_N; j += i) {
			prime[j] = false;
		}
	}
	while (true) {
		cin >> n >> m;
		if (n == 0 && m == 0) { break; }
		for (int i = 0; i <= m; i++) {
			dp[i] = false;
		}
		dp[0] = true;
		for (int i = 0; i < n; i++) { cin >> a[i]; }
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (dp[j] == true) {
					dp[j] = true;
					dp[j + a[i]] = true;
				}
			}
		}
		for (int i = m; i >= 0; i--) {
			if (dp[i] == true && prime[i] == true) {
				cout << i << endl; goto E;
			}
		}
		cout << "NA" << endl;
	E:;
	}
	return 0;
}

Measured memory_bytes: 4088
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	int width,height,map[17][17],table[17][17],sum;

	while(true){
		scanf("%d %d",&width,&height);
		if(width == 0 && height == 0)break;

		for(int i = 0; i < 17; i++){
			for(int k = 0; k < 17; k++){
				table[i][k] = 0;
				map[i][k] = 2;
			}
		}

		for(int i = 1; i <= height; i++){
			for(int k = 1; k <= width; k++){
				scanf("%d",&map[i][k]);
				if(map[i][k] == 0){
					if(i == 1){
						table[i][k] = 1;
					}else{
						if(map[i-1][k-1] != 2){
							table[i][k] += table[i-1][k-1];
						}
						if(map[i-1][k] != 2){
							table[i][k] += table[i-1][k];
						}
						if(map[i-1][k+1] != 2){
							table[i][k] += table[i-1][k+1];
						}
						if(map[i-2][k] == 2){
							table[i][k] += table[i-2][k];
						}
					}
				}else if(map[i][k] == 1){
					table[i][k] = 0;
				}else{
					if(map[i-1][k] != 2){
						table[i][k] += table[i-1][k];
					}
					if(map[i-2][k] == 2){
						table[i][k] += table[i-2][k];
					}
				}
			}
		}

		sum = 0;

		for(int k = 1; k <= width; k++){
			sum += table[height][k];
			if(map[height-1][k] == 2){
				sum += table[height-1][k];
			}
		}

		printf("%d\n",sum);
	}

	return 0;
}

Measured memory_bytes: 2552
#include<iostream>
//#include<mem.h>
#include<string>
#include<algorithm>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
ll power(ll x,ll y,ll p){
ll res = 1;x = x % p;
while (y > 0){
if (y & 1){res = (res*x) % p;}
y = y>>1;
x = (x*x) % p;}
return res;}
ll mcd(ll a,ll b){
    if(b>a)swap(a,b);
    if(b==0)return a;
    else return mcd(b,a%b);
}
ll t,n,m,k;
bool esprimo(ll n){
ll s=0;
for(ll i=1;i*i<=n;i++){
    if(n%i==0){s++;}}
if(s>=2){return false;}
return true;
}
int main(){
    //    cout<<fixed<<setprecision(2);
//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
string a,b;
cin>>a>>b;
n=a.size();
m=b.size();
int aa[n+2][m+2];
//memset(aa,0,sizeof aa);
for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
    aa[i][j]=0;

    }}
for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
        if(a[i-1]==b[j-1]){
            aa[i][j]=max(aa[i-1][j-1]+1,max(aa[i-1][j],aa[i][j-1]));
        }else{
            aa[i][j]=max(aa[i-1][j-1],max(aa[i-1][j],aa[i][j-1]));
        }
    }
}
int s=0;
for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
        s=max(s,aa[i][j]);
    }
}
ll ii,jj;
for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
        //cout<<aa[i][j]<<" ";
        if(aa[i][j]==s){
            ii=i;
            jj=j;
        }
    }
//    cout<<endl;
}
string ans="";
for(int i=n;i>0;i--){
    for(int j=1;j<=m;j++){
        if(aa[i][j]==s&&a[i-1]==b[j-1]){
            ans+=a[i-1];
            s--;
        }

    }
}

reverse(ans.begin(),ans.end());
cout<<ans;

}


Measured memory_bytes: 38840
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int64_t W, a, b;

  cin >> W >> a >> b;

  if(a + W < b)
    cout << b - a - W << endl;
  else if(b + W < a)
    cout << a - b - W << endl;
  else
    cout << 0 << endl;

  return 0;
}


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

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

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}


   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
const ll MAX_N = 1e5, MAX_M = 1e5;
ll N, M;
ll x[MAX_N], y[MAX_N];
vector<ll> vin[MAX_N] = {};
vector<ll> vout[MAX_N] = {};
ll dp[MAX_N];

ll longest_path(ll x){
  //xを始点とするlongest path
  if (dp[x] >= 0) return dp[x];
  else if (vout[x].empty()) {
    dp[x] = 0;
    return 0;
  }
  else{
    ll ans = -1;
    for(auto i = vout[x].begin(); i != vout[x].end(); i++){
      chmax(ans, longest_path(*i) + 1);
    }
    dp[x] = ans;
    return ans;
  }
}

int main(){
  cin >> N >> M;
  REP(i, M){
    ll xi, yi;
    cin >> xi >> yi;
    x[i] = xi - 1; y[i] = yi - 1;
    //有向辺xi-1 -> yi-1
    vout[xi - 1].pb(yi - 1);
    vin[yi - 1].pb(xi - 1);
  }
  REP(i, N){
    dp[i] = -1;
  }
  ll ans = -1;
  REP(i, N){
//    dump(longest_path(i))
//    dump(vout[i].size())
//    dump(vin[i].size())
    chmax(ans, longest_path(i));
  }
  cout << ans << endl;
}


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

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl

char table[510][510];

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

    int H, W;
    cin >> H >> W;
    rep(i,H) rep(j,W) cin >> table[i][j];

    rep(i,H){
        rep(j,W){
            char c;
            if(table[i][j] == '#') c = '#';
            else if(j == W-1) c = '.';
            else if(i%2 == 0) c = '#';
            else if(j == 0) c = '#';
            else c = '.';
            cout << c;
        }
        cout << endl;
    }
    cout << endl;

    rep(i,H){
        rep(j,W){
            char c;
            if(table[i][j] == '#') c = '#';
            else if(j == 0) c = '.';
            else if(i%2 == 1) c = '#';
            else if(j == W-1) c = '#';
            else c = '.';
            cout << c;
        }
        cout << endl;
    }
    return 0;
}


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

int main(void)
{
    int a, b;
    cin >> a >> b;
    if(a == 0)
    {
        if(b != 100)
            cout << b <<endl;
        else
            cout << 101 <<endl;
    }
    else if(a == 1)
    {
        if(b != 100)
            cout << b*100 <<endl;
        else
            cout << 101*100 <<endl;
    }
    else
    {
        if(b != 100)
            cout << b*10000 << endl;
        else
        {
            cout << 101*10000 << endl;
        }
    }
}


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

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { // ans <= 1e18
  return a * (b / gcd(a, b));
}

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

  vector<ll> T(N);
  rep(i, N) cin >> T[i];

  rep(i, N - 1) T[i + 1] = lcm(T[i], T[i + 1]);

  cout << T.back() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int A;
  cin >> N >>A;
  if (( N - ( N/500 * 500 ) ) <= A ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    char c;
    cin >> c;
    if(c >= 'a' && c <= 'z') cout << 'a' << endl;
    else cout << 'A' << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <cstdlib>
#include <climits>
#include <set>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void diverta2019_2_a(vector<vector<int>> v) {

    int n = v[0][0];
    int k = v[0][1];

    if(k==1){
        
        cout << "0" <<endl;
    }else{
        

        cout << n - (k - 1)-1<<endl;
    }



}

int main() {

    //    vector<vector < string>> vec_arr_result;
    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata2();

    diverta2019_2_a(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


Measured memory_bytes: 256