akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int x, y;
  cin >> x >> y;
  int ans = 0;
  if (x == 1)
    ans += 300000;
  else if (x == 2)
    ans += 200000;
  else if (x == 3)
    ans += 100000;
  if (y == 1)
    ans += 300000;
  else if (y == 2)
    ans += 200000;
  else if (y == 3)
    ans += 100000;
  if (x == 1 && y == 1) ans += 400000;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
S = [input()]
ans = 'NO'
while S:
    S_new = []
    for s in S:
        if s[:5]=='dream'  : S_new.append(s[5:])
        if s[:7]=='dreamer': S_new.append(s[7:])
        if s[:5]=='erase'  : S_new.append(s[5:])
        if s[:6]=='eraser' : S_new.append(s[6:])
    S = S_new
    if '' in S:
        ans = 'YES'
        break

print(ans)

Measured memory_bytes: 3444
import sys
from fractions import gcd
input = sys.stdin.readline


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


a, b = map(int, input().split())
g = gcd(a, b)
print(len(set(prime_decomposition(g))) + 1)


Measured memory_bytes: 5048
N = int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]
flag = 0
count = 0

for i in range(N):
  if x[i] == y[i]:
    count += 1
    if count >= 3:
      flag = 1
  else:
    count = 0

if flag == 1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll ar[n+10],an[n+10];
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	an[n+1]=0;
	for(i=n;i>1;i--){
		if(ar[i-1]>=ar[i]){
			an[i]=an[i+1]+1;
		}
		else an[i]=0;
	}

	ll mx=0;
	for(i=2;i<=n+1;i++){
		mx=max(mx,an[i]);
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	int color[13] = { 0 };
	int count = 0, free = 0;
	int minans = 0, maxans = 0;
	REP(i, n) {
		cin >> a[i];
		a[i] /= 400;
	}
	REP(i, n) {
		if (color[a[i]] == 0 && a[i] <= 7) {
			color[a[i]]++;
			count++;
		}
		if (a[i] > 7) {
			free++;
		}
	}
	minans = count;
	if (minans == 0) {
		minans = 1;
	}
	maxans = count + free;
	cout << minans << " " << maxans << endl;
	return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    if(a + b == c || b + c == a || a + c == b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

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

    vector<pair<int, int>> p(n);
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        p[i] = make_pair(a,i+1);
    }
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());

    multiset<int> pos;
    pos.insert(0);
    pos.insert(0);
    pos.insert(n+1);
    pos.insert(n+1);

    long long int ans = 0;
    for(int i=0; i<n; i++){
        //cout << *prev(pos.lower_bound(q[i].second)) << " " << *pos.upper_bound(q[i].second) << endl;
        long long int left1  = p[i].second - *prev(pos.lower_bound(p[i].second));
        long long int left2  = *prev(pos.lower_bound(p[i].second)) - *prev(prev(pos.lower_bound(p[i].second)));
        long long int right1 = *pos.upper_bound(p[i].second) - p[i].second;
        long long int right2 = *next(pos.upper_bound(p[i].second)) - *pos.upper_bound(p[i].second);

        pos.insert(p[i].second);
        ans += p[i].first * (left1 * right2 + left2 * right1);
        //cout << p[i].first << " * (" << left1 << " * " << right2 << " + " << left2 << " * " << right1 << ")" << endl; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
    int r, c, s=0, S=0, a[101][101] = { 0 };
    scanf("%d%d", &r, &c);
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            scanf("%d", &a[i][j]);
            S += a[i][j];
        }
    }
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            s +=a[i][j];
        }
        a[i][c] = s;
        s = 0;
    }
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < r; j++) {
            s += a[j][i];
        }
        a[r][i] = s;
        s = 0;
    }
    a[r][c] = S;
    for (int i = 0; i < r+1; i++) {
        for (int j = 0; j < c+1; j++) {
            printf("%d", a[i][j]);
            if (j < c)printf(" ");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2120
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n, q;
std::string s;
char spell[200005][2];

long drop(long a){
    for(int i = 0; i < q; i++){
        if(s[a] == spell[i][0]){
            if(spell[i][1] == 'L'){
                if(a == 0){
                    return 1l;
                }else{
                    a--;
                }
            }else{
                if(a == n-1){
                    return 2l;
                }else{
                    a++;
                }
            }
        }
    }
    return 0l;
}

long binary(long flag){
    long ok, ng;
    if(flag == 1){
        ok = -1, ng = n;
    }else{
        ok = n, ng = -1;
    }
    while(std::abs(ok-ng) > 1){
        long mid = (ok+ng)/2;
        if(drop(mid) == flag){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

int main(){
    scanf("%ld%ld", &n, &q);
    std::cin >> s;
    /*
    for(int i = 0; i < q; i++){
        scanf("%c %c ", &spell[i][0], &spell[i][1]);
    }
    //*/
    for(int i = 0; i < q; i++){
        std::cin >> spell[i][0] >> spell[i][1];
    }
    /*
    printf("  %ld\n", binary(1));
    printf("  %ld\n", binary(2));
    //*/
    printf("%ld\n", binary(2)-binary(1)-1);
}


Measured memory_bytes: 900
/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int main()
{
    fast();
     string s ;
     cin>>s;
     if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
        cout<<"3\n";
     else if((s[0]=='R'&&s[1]=='R')||(s[1]=='R'&&s[2]=='R'))
     cout<<"2\n";
     else if(s[1]=='S'&&(s[0]=='R'||s[2]=='R'))
        cout<<"1\n";
     else if(s[1]=='R')
     cout<<"1\n";
     else 
        cout<<"0\n";
}


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

int t,n,m;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	if (n >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main() {
    int N; cin >> N;
    int ans = 0;
    vector<int> A(N),B(N),C(N-1);
    rep(i,N) cin >> A.at(i);
    rep(i,N) cin >> B.at(i);
    rep(i,N-1) cin >> C.at(i);
    
    rep(i,N-1) {
        ans += B.at(A.at(i)-1);
        if(A.at(i+1) == A.at(i)+1)
            ans += C.at(A.at(i)-1);
    }
    ans += B.at(A.at(N-1)-1);
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  	public static void main(String[] args) {
      	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      	int c = sc.nextInt();
      	if(b < a * c){
          System.out.println(b / a);
        } else {
          System.out.println(c);
        }
    }
}

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

typedef long long ll;

signed main()
{
    ll n; cin >> n;
    --n;
    vector<int> s;
    while(1){
        int m = n % 26;
        s.push_back(m);
        ll d = n / 26L;
        if (d == 0L) break;
        n = d-1;
    }
    for (int i = s.size(); i > 0; --i){
        printf("%c", s[i-1]+'a');
    }
    puts("");
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
	int N;
	cin >> N;
	int sum = 0;
	for(int i = 0; i < N; i++){
	int l, r;
	cin >> l >> r;
	sum += r-l+1;
   
 }

   cout << sum << endl;
  
    }

Measured memory_bytes: 3644
# import bisect
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys

sys.setrecursionlimit(10 ** 5 + 10)


# input = sys.stdin.readline

def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    AA = Counter(A).most_common()

    num=len(AA)-K
    ans=0
    for i in range(1,num+1):
        ans+=AA[-i][1]
    print(ans)

resolve()

Measured memory_bytes: 101576
// practice with Dukkha, coached by rainboy
#include <algorithm>
#include <iostream>

using namespace std;

const int INF = 0x3f3f3f3f;

int main() {
	int n; cin >> n;
	long long asum = 0;
	int bmin = INF;
	while (n--) {
		int a, b; cin >> a >> b;
		asum += a;
		if (a > b)
			bmin = min(bmin, b);
	}
	cout << (bmin != INF ? asum - bmin : 0) << '\n';
	return 0;
}


Measured memory_bytes: 3616
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll H = 10+1;
const ll W = 1000+1;
const ll LMT = (1LL<<H);
ll val[H][W];
ll d[H][W];
ll h,w,k;

int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
    cin>>h>>w>>k;
    for(ll i=1;i<=h;i++)
    {
    	string s;
    	cin>>s;
    	for(ll j=1;j<=w;j++)
    	{
    		val[i][j]=s[j-1]-'0';
    	}
    }
    ll ans=max(1LL,(h-1))*max(1LL,(w-1));
    for(ll mask=0;mask<(1LL<<(h-1LL));mask++)
    {
    	ll cuts=0;
    	memset(d,0,sizeof(d));
    	ll id=1;
    	ll u=1;
    	for(ll i=0;i<(h-1LL);i++)
    	{
    		if(mask&(1LL<<i))
    		{
    			cuts++;
    			for(ll j=u;j<=i+1;j++)
    			{
    				for(ll k=1;k<=w;k++)
    				{
    					d[id][k]+=val[j][k];
    				}
    			}
    			u=i+2;
    			++id;
    		}
    	}
    	//cout<<u<<endl;
    	for(ll j=u;j<=h;j++)
		{
			for(ll k=1;k<=w;k++)
			{
				d[id][k]+=val[j][k];
			}
		}
		bool val=true;
		for(ll i=1;i<=w;i++)
		{
			for(ll j=1;j<=id;j++)
			{
				if(d[j][i]>k)
				{
					val=false;
					break;
				}
			}
		}
		ll ld[id+1];
		memset(ld,0,sizeof(ld));
		for(ll i=1;i<=w;i++)
		{
			bool overload=false;
			for(ll j=1;j<=id;j++)
			{
				ld[j]+=d[j][i];
				//cout<<j<<"_"<<ld[j]<<endl;
				if(ld[j]>k)
				{
					overload=true;
					break;
				}
			}
			if(overload)
			{
				cuts++;
				for(ll j=1;j<=id;j++)
				{
					ld[j]=0LL;
				}
				for(ll j=1;j<=id;j++)
				{
					ld[j]+=d[j][i];
				}
			}
		}
		if(val)
		ans=min(ans,cuts);
		// for(ll i=1;i<=id;i++)
		// {
		// 	for(ll j=1;j<=w;j++)
		// 	{
		// 		cout<<d[i][j]<<" ";
		// 	}cout<<endl;
		// }
		// cout<<mask<<" "<<cuts<<" "<<val<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	char S[128];
	int mikakosi;
	if (scanf("%127s", S) != 1) return 1;
	if (sscanf(S, "2019/%d", &mikakosi) == 1) {
		if (mikakosi <= 4) {
			puts("Heisei");
		} else {
			puts("TBD");
		}
	} else {
		puts("ERROR!");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(A);
  vector<int> x(M);
  vector<int> y(M);
  vector<int> c(M);

  for(int i = 0; i < A; i++){
    cin >> a[i];
  }
  for(int i = 0; i < B; i++){
    cin >> b[i];
  }
  for(int i = 0; i < M; i++){
    cin >> x[i] >> y[i] >> c[i];
  }

  vector<int>::iterator iter = min_element(a.begin(), a.end());
  size_t amin = distance(a.begin(), iter);
  iter = min_element(b.begin(), b.end());
  size_t bmin = distance(b.begin(), iter);

  vector<int> pmin;
  pmin.push_back(a[amin] + b[bmin]);

  for(int i = 0; i < M; i++){
    pmin.push_back(a[x[i] - 1] + b[y[i] - 1] - c[i]);
  }

  iter = min_element(pmin.begin(), pmin.end());
  size_t index = distance(pmin.begin(), iter);
  cout << pmin[index] << endl;

  return 0;
}


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

int main() {
   int a;
   cin>>a;
   vector<int> vec(a);
   rep(i,a){
       cin>>vec.at(i);
   }
   int count =0;
   bool flag=true;
   while(flag==true){
       rep(i,a){
           if(vec.at(i)%2==0){
            vec.at(i)=vec.at(i)/2;
           }
           else{
               flag=false;
           }
       }
       if(flag==true){
           count++;
       }
   }
    cout<<count<<endl;
}



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

#define START 0;
#define LEFT 1;
#define UP 2;
#define DIAG 3;

int main(int argc, char *argv[]) {
    string s, t;
    cin >> s;
    cin >> t;

    long long lcs[s.size() + 1][t.size() + 1];

    for (int i = 0; i < s.size() + 1; i++) {
        lcs[i][0] = 0;
    }
    for (int i = 0; i < t.size() + 1; i++) {
        lcs[0][i]  = 0;
    }

    for (int i = 1; i < s.size() + 1; i++) {
        for (int j = 1; j < t.size() + 1; j++) {
            if (s[i-1] == t[j-1]) {
                lcs[i][j] = lcs[i-1][j-1] + 1;
            } else {
                lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
            }
        }
    }

    /*
    for (int i = 0; i < s.size() + 1; i++) {
        for (int j = 0; j < t.size() + 1; j++) {
            cout << lcs[i][j] << " ";
        }
        cout << endl;
    }

    cout << endl;
     */


    string answser = "";
    long i = s.size();
    long j = t.size();
    while (i > 0 && j > 0) {
        // lcs[i-1][j] --> lcs[i][j]
        if (lcs[i-1][j] == lcs[i][j]) {
            i--;
        }

        // lcs[i][j-1] --> lcs[i][j]
        else if (lcs[i][j-1] == lcs[i][j]) {
            j--;
        }

        else {
            answser = s[i-1] + answser;
            i--;
            j--;
        }
       // cout << answser << endl;
    }

    cout << answser;
    return 0;
}

Measured memory_bytes: 70656
#include <stdio.h>

void readInt(int *x) {
	scanf("%d", x);
	return;
}
void readInts(int n, int arr[]) {
	int i;
	for (i=0;i<n;i++) {
		readInt(&arr[i]);
	}
}
void readChar(char *x) {
	scanf("%c", x);
	return;
}
void readChars(int n, char x[]) {
	scanf("%s", x);
	return;
}
void printInts(int n, int *arr) {
	int i;
	for (i=0;i<n;i++) {
		printf("%d ", arr[i]);
	}
	printf("\n");
	return;
}

int main(int argc, char const *argv[])
{
	int x[3];
	readInts(3,x);

	if (x[0]==x[1] && x[0]!=x[2]) {
		printf("Yes\n");
	} else if(x[0]==x[2] && x[0]!=x[1]) {
		printf("Yes\n");
	} else if(x[1]==x[2] && x[0]!=x[1]) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}


	return 0;
}

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

int n, m, q;
vector<int> a, b, c, d;

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

int check(vector<int> hoge) {
    int res = 0;
    for (int i = 0; i < q; i++) {
        if (hoge[b[i]] - hoge[a[i]] == c[i]) {
            res += d[i];
        }
    }
    return res;
}

int main() {
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }
    queue<vector<int>> cand;
    for (int i = 1; i <= m; i++) {
        cand.push(vector<int>(1, i));
    }
    int ans = 0;
    while (!cand.empty()) {
        auto now = cand.front();
        cand.pop();
        if (now.size() == n) {
            chmax(ans, check(now));
        } else {
            for (int i = now.back(); i <= m; i++) {
                auto next = now;
                next.push_back(i);
                cand.push(next);
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())
#define ten(n) ((int)1e##n)
using ll = long long;

const int MOD = ten(9) + 7;
const int N = ten(4);
ll inverse[N];
void init_inverse() {
	inverse[1] = 1;
	for (int i = 2; i < N; i++) inverse[i] = (MOD - MOD / i) * inverse[MOD%i] % MOD;
}

ll fact[N], infact[N];
void init_fast_fact() {
	init_inverse();
	fact[0] = fact[1] = 1;
	for (int i = 2; i < N; i++) fact[i] = fact[i - 1] * i % MOD;
	infact[0] = infact[1] = 1;
	for (int i = 2; i < N; i++) infact[i] = infact[i - 1] * inverse[i] % MOD;
}

ll fast_nCk(int n, int k) {
	if (n < 0 || k < 0) return 0;
	if (k > n) return 0;
	ll ret = fact[n] * infact[k] % MOD * infact[n - k] % MOD;
	return ret;
}


ll pseudo_catalan(int a, int b, int c) {
	if (c == a - 1) b--, c--;
	if (c == b - 1) a--, c--;
	ll ret = fast_nCk(a + b - 2, a - 1) - fast_nCk(a + b - 2, c - 1);
	if (ret < 0) ret += MOD;
	return ret;
}

int solve(int n, int m) {
	init_fast_fact();
	vector<ll> magic = { 1, 1, 3 };
	for (int i = 3; i <= n; i++) {
		ll tmp = 3 * (i + 1) * magic[i - 1] + 8 * (i - 2) * magic[i - 2] - 24 * (i - 2) * magic[i - 3];
		magic.push_back(tmp % MOD * inverse[i + 1] % MOD);
		if (magic[i] < 0) magic[i] += MOD;
	}

	vector<ll> power_of_2;
	power_of_2.push_back(1);
	FOR(i, n) power_of_2.push_back(power_of_2.back() * 2 % MOD);

	ll ans = 0;
	FOR(s, n + 1) {
		const int rem = n - s;
		if (rem < m) continue;
		if ((rem - m) % 2 != 0) continue;
		const int B = (rem - m) / 2;
		const int A = rem - B;

		const ll a1 = B == 0 ? 1 : pseudo_catalan(A , B + 1, B);
		const ll s_ans = a1 * power_of_2[B] % MOD * magic[s] % MOD;
		ans += s_ans;
	}

	return int(ans % MOD);
}

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int m = sz(s);
	int ans = solve(n, m);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,b,a[15],sum,c;
    scanf("%d",&n);

    for(i=0; i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    b=a[0];
    sum=0;
    for(i=0,c=0; i<n; i++)
    {
        sum=sum+a[i];
        if(a[i]>b)
        {
            c=i;
            b=a[i];

        }
    }
    printf("%d",sum-a[c]/2);
    return 0;


}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  str flag = "YAKI";
  str a; cin >> a;
  fin(a.substr(0, 4) == flag?"Yes":"No")
  return;
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


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;

int main(){
    int n,m;
    string s;
    cin>>n>>m>>s;
    reverse(s.begin(),s.end());
    vector<int>ans;
    int i=0;
    while(i!=n){
        bool ok=false;
        for(int j=i+m; j>i; --j){
            if(j>n)continue;
            if(s[j]=='0'){
                ok=true;
                ans.push_back(j-i);
                i=j;
                break;
            }
        }
        if(!ok){cout<<-1<<endl; return 0;}
    }
    reverse(ans.begin(),ans.end());
    rep(i,ans.size())cout<<ans[i]<<" ";
}

Measured memory_bytes: 3976
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

#define INF 100000

int main() {
    int N, ans = 0;
    cin >> N;
    vector<int>p(N + 2, 0);
    for (int i = 1; i <= N; i++) {
        cin >> p[i];
    }

    for (int i = 1; i <= N; i++) {
        if (i == p[i]) {
            swap(p[i], p[i + 1]);
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
n,m = gets.chomp.split.map(&:to_i)
xs = gets.chomp.split.map(&:to_i).sort
dist = xs.each_cons(2).map{|a,b| (a-b).abs}.sort
ans = 0
[0,m - n].max.times do
	ans += dist.shift
end

puts ans

Measured memory_bytes: 14656
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N = input()
cnt = 0
for i in range(len(N)):
    cnt += int(N[i])

if cnt % 9 == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 84028
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
using namespace std;
int l[200010], r[200010];
int main() {
    int N,M;
    scanf("%d%d",&N,&M);
    rep(i,0,N){
        int L,R;
        scanf("%d%d",&L,&R);
        if(L) l[L-1]++;
        if(R<=M) r[R-1]++;
    }
    rer(i,M-1,0){
        l[i]+=l[i+1];
    }
    rep(i,1,M){
        r[i]+=r[i-1];
    }
    int res=1e8;
    int ans=0;
    rep(i,0,M){
        res=min(res-1,l[i]);
        if(res==0){
            ans=i;
            break;
        }
        if(i==M-1) ans=M;
    }
    res=1e8;
    rep(i,0,M){
        res=min(res-1,r[M-1-i]);
        if(res==0){
            ans+=i;
            break;
        }
        if(i==M-1) ans+=M;
    }
    printf("%d\n", max(0,N-min(ans,M)));
}

Measured memory_bytes: 1792
import sys

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

for e in sys.stdin:
    n = int(e)
    print(len(primes(n)))


Measured memory_bytes: 16816
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int binary[64][maxn];
vector<int> v[maxn];
int tuvshin[maxn];

string lol(int n) {
    string s;
    while(n > 0) {
        s += to_string(n%2);
        n /= 2;
    }
    return s;
}

int main() {
    int n;
    cin >>n;
    memset(binary, -1, sizeof binary);
    for(int i = 0; i < n; i++) {
        int a;
        cin >>a;
        for(int j = 1; j <= a; j++) {
            int x;
            cin >>x;
            v[i].push_back(x);
            binary[0][x] = i;
        }
    }
    
    for(int i = 1; i <= 32; i++) 
        for(int j = 1; j < n; j++) 
            binary[i][j] = binary[i-1][binary[i-1][j]];
    
    queue<pair<int, int> > pq;
    pq.push(make_pair(0, 0));
    while(!pq.empty()) {
        int x = pq.front().first;
        int k = pq.front().second;
        tuvshin[x] = k;
        pq.pop();
        for(int i = 0; i < v[x].size(); i++) {
            pq.push(make_pair(v[x][i], k+1));
        }
    }
    int t;
    cin >>t;
    while(t--) {
        int a, b;
        cin >>a >>b;
        if(tuvshin[a] > tuvshin[b]) {
            int k = tuvshin[a] - tuvshin[b];
            string s = lol(k);
            for(int i = 0; i < s.size(); i++)
                if(s[i] == '1') 
                    a = binary[i][a];
        }
        if(tuvshin[b] > tuvshin[a]) {
            int k = tuvshin[b] - tuvshin[a];
            string s = lol(k);
            for(int i = 0; i < s.size(); i++)
                if(s[i] == '1') 
                    b = binary[i][b];
        }
        while(a != b) {
            int l = 0, r = 64;
            while(l <= r) {
                int mid = (r+l)>>1;
                if(binary[mid][a] == binary[mid][b]) {
                    r = mid-1;
                }
                else l = mid+1;
            }
            if(l != 0)l--;
            a = binary[l][a];
            b = binary[l][b];
        }
        cout<<a<<"\n";
    }
}


Measured memory_bytes: 34072
#include<stdio.h>
 
int main(void){
  int n,i;
  int max;
  int a[7]={1,2,4,8,16,32,64};
  
  scanf("%d",&n);
  for(i=0;i<7;i++){
    if(a[i]<=n){
      max=a[i];
    }
  }
  printf("%d",max);
    
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
#include <cstdio>
using namespace std;

typedef long long ll;
typedef pair<ll,int> P;
typedef pair<int,P> P2;
const int inf=1000000000;
int main() {
	int n,k;
	cin>>n>>k;
	bool d[10]={};
	for(int i=0;i<k;++i){
		int d1;
		cin>>d1;
		d[d1]=true;
	}
	bool flg;
	for(int i=n;i<n*10+1;++i){
		int k=i;
		flg=true;
		for(int j=0;j<5;++j){
			int k2=k%10;
			if(d[k2]){
				flg=false;
			}
			k=k/10;
			if(k==0)break;
		}
		if(flg){
			cout<<i<<endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
int main(){
  for(;;){
    vector<int> lot(5);
    int ans = 0;
    if(scanf("%d",&lot[0]) == EOF) break;
    for(int i=1; i<5; i++) scanf(",%d",&lot[i]);
    sort(lot.begin(),lot.end());
    map<int,int> card;
    for(int i=0; i<5; i++) card[lot[i]]++;
    for(map<int,int>::iterator it = card.begin(); it!=card.end(); it++){
      if(it->second == 2) ans+=2; 
      if(it->second == 3) ans+=3;
      if(it->second == 4) ans+=6;
    }
    if(ans == 2) cout <<"one pair"<<endl;
    if(ans == 3) cout <<"three card"<<endl;
    if(ans == 4) cout <<"two pair"<<endl;
    if(ans == 5) cout <<"full house"<<endl;
    if(ans == 6) cout <<"four card"<<endl;
    if(lot[0]+1 == lot[1] && lot[1]+1 == lot[2] && lot[2]+1 == lot[3] && lot[3]+1 == lot[4]) cout <<"straight"<<endl;
    else if(lot[0] == 1 && lot[1] == 10 && lot[2] == 11 && lot[3] == 12 && lot[4] == 13) cout <<"straight"<<endl;
    else if(ans == 0) cout<<"null"<<endl;
  }
  return 0;
}

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

int main(void){
    int m, f, r;
    while(cin >>  m >> f >>r){
        if (m == -1 && f == -1 && r == -1) break;
        else if (m == -1 || f == -1) cout<< "F\n";
        else if (m+f >= 80 ) cout<< "A\n";
        else if (m+f >= 65 && m+f < 80) cout<< "B\n";
        else if (m+f >= 50 && m+f < 65) cout<< "C\n";
        else if (m+f >= 30 && m+f < 50) {
            if (r >= 50) cout << "C\n";
            else cout <<"D\n";
        }
        else if (m+f < 30 ) cout<< "F\n";
        
        
    }
}

Measured memory_bytes: 1116
import collections
N=int(input())
A=[int(x) for x in input().split()]
C=collections.Counter(A)
C=sorted(list(C.items()),reverse=True)
li=[]
for i,j in C:
  if j>=4:
    li.append(i)
    break
  if j>=2:
    li.append(i)
  if len(li)==2:
    break
if len(li)==0:
  print(0)
if len(li)==1:
  print(li[0]**2)
if len(li)==2:
  print(li[0]*li[1])

Measured memory_bytes: 22052
#include <stdio.h>
int main(void) {
  int vsum[100], R,C,r,c;

  scanf("%d %d\n", &R, &C);
  for (c = 0; c < C; c++)
    vsum[c] = 0;

  for (r = 0; r < R; r++) {
    int hsum = 0;
    for (c = 0; c < C; c++) {
      int num;
      scanf("%d ", &num);
      printf("%d ", num);
      hsum = hsum + num;
      vsum[c] = vsum[c] + num;
    }
    printf("%d\n", hsum);
  }

  {
    int hvsum = 0;
    for (c = 0; c < C; c++) {
      printf("%d ", vsum[c]);
      hvsum = hvsum + vsum[c];
    }
    printf("%d\n", hvsum);
  }

  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 1e+5;
char tmp[maxn];
int main() {
	//freopen("in","r",stdin);
	cin>>tmp;
	int n; cin>>n;
	while(n--) {
		char op[1000]; cin>>op;
		if(!strcmp(op,"print")) {
			int a, b; cin>>a>>b;
			for(int i=a;i<=b;i++) cout<<tmp[i];
			cout<<endl;
 		} else if(!strcmp(op,"replace")) {
			int a, b; cin>>a>>b;
			char str[maxn]; cin>>str; 
			int k = 0;
			for(int i=a;i<=b;i++) tmp[i] = str[k++];
		} else {
			int a, b; cin>>a>>b;
			for(int i=a,j=b;i<j;i++,j--) swap(tmp[i],tmp[j]);
		}
	}
	return 0;
}


Measured memory_bytes: 3104
s = input()
n = len(s)

p = 0
ans = 0

for i in range(n):
    s1 = s[i]
    if s1 == 'g':
        p += 1
    else:
        p -= 1
    n -= 1
    if p >= n:
        break

for i in range(n):
    if s[-i-1] == 'g':
        ans += 1

print(ans)


Measured memory_bytes: 9072
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;
typedef long long  ll;
typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> multi_set;
#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 100+7;
const ll INF = 1e8;

ll A[DIM];
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n,m;
    cin>>n>>m;
    ll sum = 0;
    forn(i,n){
        cin>>A[i];
        sum+=A[i];
    }
    m*=4;
    ll need = sum/m+(sum%m!=0);
    ll cnt = 0;
    forn(i,n){
        if (A[i]>=need)cnt++;
    }
    if (cnt>=m/4)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  VI d(n);
  rep(i,n) cin >> d[i];
  
  sort(d.begin(),d.end());
  int ans=0;
  rep(k,100010){
    VI::iterator low = lower_bound(d.begin(),d.end(),k);
    if(low - d.begin() == n/2) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 768
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include <functional>
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  char s[5000];
  char slist[30000][6];
  int K,count=0;

  cin>>s;

  cin>>K;

  int len=strlen(s);
  len=min(len,5);


  for(int i=1;i<=len;i++){ //候補を列挙
    for(int j=0;j<strlen(s)-i+1;j++){
      strncpy(slist[count],s+j,i);
      count++;
    }
  }
  strncpy(slist[0],s,1);


  char ans[6][5];
  for(int i=0;i<5;i++){
    strcpy(ans[i],"zzzzz");
  }

  for(int i=0;i<count;i++){
    if(strcmp(slist[i],ans[0]) < 0){
      strcpy(ans[0],slist[i]);
    }
  }
  for(int i=0;i<count;i++){
    if(strcmp(slist[i],ans[1]) < 0&&strcmp(slist[i],ans[0])>0){
      strcpy(ans[1],slist[i]);
    }
  }
  for(int i=0;i<count;i++){
    if(strcmp(slist[i],ans[2]) < 0&&strcmp(slist[i],ans[1])>0){
      strcpy(ans[2],slist[i]);
    }
  }
  for(int i=0;i<count;i++){
    if(strcmp(slist[i],ans[3]) < 0&&strcmp(slist[i],ans[2])>0){
      strcpy(ans[3],slist[i]);
    }
  }
  for(int i=0;i<count;i++){
    if(strcmp(slist[i],ans[4]) < 0&&strcmp(slist[i],ans[3])>0){
      strcpy(ans[4],slist[i]);
    }
  }
  for(int i=0;i<count;i++){
    if(strcmp(slist[i],ans[5]) < 0&&strcmp(slist[i],ans[4])>0){
      strcpy(ans[5],slist[i]);
    }
  }



/*
  for(int i=0;i<6;i++){
    cout<<"ans["<<i<<"]:"<<ans[i]<<"\n";
  }
*/
  cout<<ans[K-1];

  return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		StringBuilder ans = new StringBuilder();
		for(int i=0;i<s.length();i++) {
			if(i%2==0)
				ans.append(s.charAt(i));
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 23956
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0;i <n;i++)
#define RFOR(i, n) for(int i = n;i >= 0;i--)
#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 INF 999999999

using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  cout<<min(min(a+b,a+c),b+c)<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,h,w = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(list)
for i in range(n):
    r,c,a = list(map(int, input().split()))
    r -= 1; c -= 1
    c += h
    ns[r].append((a,c))
    ns[c].append((a,r))
class UnionFindTree:
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n
        self.es = [0]*n

    def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

    def connect(self, i, j):
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            self.es[ri] += 1
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
            self.es[rj] += self.es[ri] + 1
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]
            self.es[ri] += self.es[rj] + 1

def selectEdge(ns):
    """各頂点に1本以下の接続枝を割り当てて、重み最大化
    """
    from heapq import heappop as hpp, heappush as hp
    q = []
    for u in ns.keys():
        for a,v in ns[u]:
            if u<v:
                hp(q, (-a,(u,v)))
    # 辺を選択できる = 選択した場合の連結成分において頂点数>=枝数
    uf = UnionFindTree(h+w)
    ans = 0
    while q:
        a, (u,v) = hpp(q)
        a *= -1
        ru = uf.root(u)
        rv = uf.root(v)
        if ru==rv and uf.es[ru]<uf.size[ru]:
            uf.connect(u,v)
            ans += a
        elif ru!=rv and (uf.es[ru]+uf.es[rv]+1) <= (uf.size[ru]+uf.size[rv]):
            uf.connect(u,v)
            ans += a
    return ans,uf
ans,uf = selectEdge(ns)
print(ans)

Measured memory_bytes: 135124
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
long long int m=1000000007;
long long int power(long long int p,long long int k)
{
long long int a=1;
while(k)
{
if(k&1)
a=(a*p)%m;
p=(p*p)%m;
k>>=1;
}
return a;
}
int main()
{
ll a;
string s;
cin>>a;
cin>>s;
if(a>=3200)
cout<<s;
else
cout<<"red";
return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int ans;
  if ((n-1)%(k-1) == 0) ans = (n-1)/(k-1);
  else ans = (n-1)/(k-1)+1;
  cout << ans << endl;
}
  
  

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

template<class t>
vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
  sort(line.begin(),line.end(),comp);
  return line;
}

template<class t>
vector<t> reversed(vector<t> line){
  reverse(line.begin(),line.end());
  return line;
}

int main(){
  ll n = in();
  ll k = in();
  n %= k;
  cout<< min(n,k-n) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
  ll ans = 0;
  for (int i = 0; i < N-1; i++) {
    ans += B[A[i]-1];
    if(A[i]+1 == A[i+1]){
      ans += C[A[i]-1];
    }  
  }
  ans += B[A[N-1]-1];
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), std::move(B), std::move(C));
}


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

int main()
{
    int k;
    int x,y;

    scanf("%d",&k);
    if(k%2)
    {
        x = k/2+1;
        y = k-x;
    }
    else
    {
        x = y = k/2;
    }
    printf("%d\n",x*y);

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
rate = [0] * 8
x = 0
for i in a:
    if 1 <= i <= 399:
        rate[0] += 1
    elif 400 <= i <= 799:
        rate[1] += 1
    elif 800 <= i <= 1199:
        rate[2] += 1
    elif 1200 <= i <= 1599:
        rate[3] += 1
    elif 1600 <= i <= 1999:
        rate[4] += 1
    elif 2000 <= i <= 2399:
        rate[5] += 1
    elif 2400 <= i <= 2799:
        rate[6] += 1
    elif 2800 <= i <= 3199:
        rate[7] += 1
    else:
        x += 1
ans = 8 - rate.count(0)
print(max(1, ans), ans+x)

Measured memory_bytes: 3064
s = input()
t = input()
s=s[::-1]
t=t[::-1]

len_s = len(s)
len_t = len(t)

for i in range(len_s-len_t+1):
  flag = True
  for j in range(len_t):
    if s[i+j]!=t[j] and s[i+j]!="?":
      flag = False
      break
  if flag:
    print((s[0:i]+t+s[i+len_t:len_s]).replace("?","a")[::-1])
    exit()
print("UNRESTORABLE")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<deque>
#include<numeric>
#include<algorithm>
#include<unordered_map>
#include<cmath>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);

ll n;
vector<ll> d;

ll f(ll a, ll b) {
	return ll(max(log10(a), log10(b))) + 1;
}

ll divisor(ll n) {
	ll ret = ll(log10(n)) + 1;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ll a = i;
			ll b = n / i;
			ll tmp = f(a, b);
			if (tmp < ret)
				ret = tmp;
		}
	}
	return ret;
}

int main(void) {
	cin >> n;
	cout << divisor(n) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
 
#define int long long
#define endl '\n'

#define IOS ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
 
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vi>
#define vp vector<pii>
#define vs vector<string>
#define all(v) v.begin(),v.end()

#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define ff  first
#define ss  second
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
 
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
     
#define pi 3.14159265358979323846264338327950L
#define MOD 1000000007

int32_t main(){

    
     int x,y;
     cin>>x>>y;
     if(y%2==0&&(x*2)<=y&&(x*4)>=y)
      cout<<"Yes";
    else
      cout<<"No";
    
  return 0;
}




Measured memory_bytes: 3568
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<climits>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

struct SegTree{
    ll N;
    vl dat;
    void init(int _N){
        N=1;
        while(N<_N)N*=2;
        dat=vl(N*2-1,0);
    }
    void update(ll k,ll val){
        k+=N-1;
        dat[k]=val;
        while(k){
            k=(k-1)/2;
            dat[k]=max(dat[k*2+1],dat[k*2+2]);
        }
    }
    ll getMax(ll a,ll b,ll k=0,ll l=0,ll r=-1){
        if(r==-1)r=N;
        if(r<=a||b<=l)return 0;
        if(a<=l&&b>=r)return dat[k];
        ll v1=getMax(a,b,k*2+1,l,(l+r)/2);
        ll v2=getMax(a,b,k*2+2,(l+r)/2,r);
        return max(v1,v2);
    }
};

int main(){
    ll N;
    scanf("%lld",&N);

    SegTree seg;
    seg.init(N);
    ll ans=0;

    for(int i=0;i<N;i++){
        ll weight;
        scanf("%lld",&weight);
        seg.update(weight-1,seg.getMax(0,weight)+weight);
        ans=max(ans,seg.getMax(weight-1,weight));
    }
    printf("%lld\n",N*(N+1)/2-ans);

    return 0;
}

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

using namespace std;

bool compare(string s1, string s2){
  if(s1 + s2 < s2 + s1) return true;
  return false;
}

int main(){
	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  
  	int n, l;
  	string answer = "";
  	cin >> n >> l;
  	vector<string> v(n);
  	for(int i = 0; i < n; i++){
    	cin >> v[i];
    }
  	sort(v.begin(), v.end(), compare);
  	for(int i = 0; i < n; i++){
    	answer += v[i];
    }
  	cout << answer << "\n";
}

Measured memory_bytes: 3696
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
 
#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int n,ans;
char s[300][300];
bool flag;

int main(){
	cin>>n;
	lp(n)
		LP(n,j)
			cin>>s[i][j];
	ans=0;
	lp(n){
		flag=false;
		LP(n,j){
			LP(n,k){
				if(s[(i+j)%n][k]!=s[(i+k)%n][j]){
					flag=true;
					break;
				}
			}
			if(flag)break;
		}
		if(flag==false)
			ans+=n;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384