akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define M 1000000007
ll dp[1005][1005],kai[1005];
ll n,a,b,c,d;
ll pw(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)res=res*x%M;
        y>>=1;
        x=x*x%M;
    }
    return res;
}
ll cm(ll x,ll y){
    return kai[x]*pw(kai[y],M-2)%M*pw(kai[x-y],M-2)%M;
}
ll dfs(ll x,ll y){
    if(x==0)return 1;
    if(y==b+1)return 0;
    if(dp[x][y]!=-1)return dp[x][y];
    ll s=dfs(x,y+1),t=1;
    for(ll i=1;i<c&&i*y<=x;i++)t=t*cm(x-(i-1)*y,y)%M;
    for(ll i=c;i<=d&&i*y<=x;i++){
        t=t*cm(x-(i-1)*y,y)%M;
        s=(s+t*pw(kai[i],M-2)%M*dfs(x-i*y,y+1)%M)%M;
    }
    return dp[x][y]=s;
}
int main(void){
    scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
    kai[0]=1;
    for(ll i=1;i<=n;i++)kai[i]=kai[i-1]*i%M;
    for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)dp[i][j]=-1;
    printf("%lld\n",dfs(n,a));
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int del=(h2-h1)*60+(m2-m1);
    cout<<max(0,del-k)<<"\n";
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    int t=1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
import itertools
def main():
    n=int(input())
    P=tuple(map(int,input().split()))
    Q=tuple(map(int,input().split()))
    L=[i for i in range(1,n+1)]
    S=itertools.permutations(L,n)
    ans=0
    flag=1
    i=0
    if P==Q:
        print(0)
        exit()
    for s in S:
        i+=1
        if s==P or s==Q:
            if flag:
                ans -= i
                flag =0
            else:
                ans += i
                break
    print(ans)
main()

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const double pi=3.1415926536;
#define fo(i,n) for( ll int i=0;i<n;++i)
#define fos(j,i,n) for(ll int j=i;j<n;++j)
#define N 100004
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define abs(x) ((x)<0?(-(x)):(x))
#define dis(k) cout << k << endl
#define forr(i,n) for( ll int i= n-1;i>=0;--i)
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define ve vector
#define fi first
#define se second
#define setzero(a) memset(a,0,sizeof(a))
#define setinf(a) memset(a,0x7F,sizeof(a))
typedef ve< ll > vi;
typedef ve< vi > vvi;
typedef pair< ll ,ll > ii;


//weird debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


/*Don't just sit and hope that God will solve this
fucking do something, try to observe or solve it a different way.
Use that pen and paper.
If nothing works take a deep breath and start again.*/


void solve(){
	ll n,k;
	cin >> n >> k;
	vi a(n);
	vi dp(n,INF);
	dp[0]=0;
	fo(i,n) cin >> a[i];
	fo(i,n) {
		for(ll j=i-1;j>=max(i-k,0ll);--j)
			dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
	}
	dis(dp[n-1]);
	
}

int main(){
	fast;
	int t=1;
	int tt=1;
	//cin >> t;

	while(t--){
		//cout << "Case #" << tt << ": " ;
		tt++;
		solve();
	}
	return 0;
}



Measured memory_bytes: 4776
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin>>str;
    if(str.length()==3)
    {
        for(int x: str)
        {
            if(x=='7')
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        cout<<"No"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3596
// Alapan
// IIITH

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

// data types
#define ll long long int
#define ld long double

//funtion macros


// stl
#define lp(var,start,end) for (ll var = start; var <=end ; ++var)
#define ilp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define sz(x) ((ll)((x).size()))

#define mod 1000000007

// utility functions
ll max(ll a, ll b){
    if(a>b)return a;
    return b;
}

ll min(ll a, ll b){
	if(a<b)return a;
    return b;
}

ll power(ll x, ll y, ll m=mod){
	if(y<0){
		x = power(x,m-2);
		y = -y;
	}
	ll ans=1;
	x = x % m;
	while(y){
		if(y&1) ans = (ans*x)%m;
		y=y/2;
		x=(x*x)%m;
	}
	return ans;
}

ll factorial(ll n, ll m=mod){
    ll ans = 1;
	ll i = 1;
    while(i<=n){
        ans = (ans*i)%m;
        i++;
    }
    return ans;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = power(10,n);
    ll rem = (2*power(9,n))%mod;
    ll add = power(8,n);
    ans = (ans - rem + mod)%mod;
    ans = (ans+add)%mod;
    cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
main(){
  int a,b,c,d,a1,a2,b1,b2;
  cin>>a1>>b1>>a2>>b2>>a>>b>>c>>d;
  int x=a1*a+b1*b+a1/10*c+b1/20*d;
  int y=a2*a+b2*b+a2/10*c+b2/20*d;
  if(x==y)cout<<"even"<<endl;
  else if(x>y)cout<<"hiroshi"<<endl;
  else cout<<"kenjiro"<<endl;
}

Measured memory_bytes: 3096
public class Hello{
    public static void Main(){

        string[] num = System.Console.ReadLine().Split(' ');
        int A = int.Parse(num[0]);
        int B = int.Parse(num[1]);
        int C = int.Parse(num[2]);
        
        if(C >= A && C <= B){
            System.Console.WriteLine("Yes");
        }else{
            System.Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int i,l;
    char s[110000];
    while(scanf("%s",s)!=EOF){

        l=strlen(s);
        for(i=0;i<l;i=i+2){
            printf("%c",s[i]);
        }
        printf("\n");

    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long LM = 1LL << 60;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    map<int, int> mp1, mp2;
    int min1 = n, min2 = n;
    long ans = (n - 2) * (long long)(n - 2);
    for (int i = 0; i < q; ++i) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            auto itr = mp1.lower_bound(x);
            if (itr == mp1.begin()) {
                mp1[x] = min2;
                ans -= min2 - 2;
            }
            else {
                --itr;
                ans -= itr->second - 2;
                mp1[x] = itr->second;
            }
            min1 = min(min1, x);
        }
        else {
            auto itr = mp2.lower_bound(x);
            if (itr == mp2.begin()) {
                mp2[x] = min1;
                ans -= min1 - 2;
            }
            else {
                --itr;
                ans -= itr->second - 2;
                mp2[x] = itr->second;
            }
            min2 = min(min2, x);
        }
        // cout << ans << '\n';
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 13020
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;

int mat[maxn][maxn], dp[maxn][maxn];

int main()
{
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#endif
    int m, n;
    memset(dp, 0x3f, sizeof(dp));
    scanf("%d%d ", &m, &n);
    for (int i = 0; i != m; ++i) {
        for (int j = 0; j != n; ++j) {
            mat[i][j] = getchar() == '.';
        }
        getchar();
    }
    dp[0][0] = 1 - mat[0][0];
    for (int j = 1; j != n; ++j) {
        if (!mat[0][j] && mat[0][j - 1])
            dp[0][j] = dp[0][j - 1] + 1;
        else
            dp[0][j] = dp[0][j - 1];
    }
    for (int i = 1; i != m; ++i) {
        if (!mat[i][0] && mat[i - 1][0])
            dp[i][0] = dp[i - 1][0] + 1;
        else
            dp[i][0] = dp[i - 1][0];
    }
    for (int i = 1; i != m; ++i) {
        for (int j = 1; j != n; ++j) {
            int t1, t2;
            if (!mat[i][j] && mat[i][j - 1])
                t1 = dp[i][j - 1] + 1;
            else
                t1 = dp[i][j - 1];
            if (!mat[i][j] && mat[i - 1][j])
                t2 = dp[i - 1][j] + 1;
            else
                t2 = dp[i - 1][j];
            dp[i][j] = min(t1, t2);
        }
    }
    printf("%d\n", dp[m - 1][n - 1]);
}

Measured memory_bytes: 384
import string
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

S=input()
T=input()

mp1={s: 0 for s in string.ascii_lowercase}
mp2={s: 0 for s in string.ascii_lowercase}
for i in range(len(S)):
    mp1[S[i]] += 1
    mp2[T[i]] += 1

li1 = list(mp1.values())
li2 = list(mp2.values())
li1.sort()
li2.sort()

print('Yes' if li1 == li2 else 'No')

Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int main(void)
{
    int a,b,t;
    cin >> a >> b >> t;
    int res = t / a * b;
    cout << res << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long ll;
const int maxn = 100005;
const ll mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;

int n,m;
int a[maxn];
char s[maxn];

int main()
{
    while(~scanf("%d",&n))
    {
        int ans1=0;
        int anss;
        for(int i=0;i<n;i++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            if(ans1<a)
            {
                ans1=a;
                anss=b;
            }
        }
        printf("%d\n",ans1+anss);
    }
}


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


int main(){
	int h, w;
	cin >> h >> w;

	int ch, cw;
	cin >> ch >> cw;

	int dh, dw;
	cin >> dh >> dw;

	vector<vector<string>> map;
	for (int i = 0; i<h; i++){
		string ch;
		cin >> ch;

		vector<string> row;
		for (int j = 0; j<w; j++){
			row.push_back(ch.substr(j,1));
		}	
		map.push_back(row);
	}

	vector<vector<int>> wrap(h, vector<int>(w,-1));

	int diz = (h<w) ? w : h;
	unordered_set<int> next;
	unordered_set<int> away;
	next.insert((ch-1)*diz+cw-1);
	wrap[ch-1][cw-1] = 0;

	while(!next.empty()){

		while(!next.empty()){
		unordered_set<int> qp;
		for (auto l = next.begin(); l!= next.end(); ++l){
			int x = (*l)/diz;
			int y = (*l)%diz;
			int c;

			for (int i=-2; i<=2; i++){
				for (int j=-2; j<=2; j++){
					if ( x+i < 0 || x+i>= h || y+j < 0 || y+j >=w || (i==0 && j==0) ||  map[x+i][y+j] != "." ){
						continue;
					}		
								
					if (abs(i) + abs(j) == 1){
						c = 0;
					}else{
						c = 1;
					}


					if ( wrap[x+i][y+j] == -1 || wrap[x+i][y+j] > wrap[x][y] + c){

						wrap[x+i][y+j] = wrap[x][y] + c;
						if ( c == 0){
							qp.insert((x+i)*diz + y + j);
							away.erase((x+i)*diz + y + j);
						}else{
							away.insert((x+i)*diz + y + j);
						}
					}	

					if ( wrap[dh-1][dw-1] == 0){
						cout << 0;
						return 0;
					}

				}
			}
		}
		next = qp;
		}
		next = away;
		away.clear();
	}
	cout << wrap[dh-1][dw-1];

	return 0;
}



Measured memory_bytes: 39056
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    string N; cin >> N;
    if (N[0] == N[1] and N[1] == N[2]) cout << "Yes" << endl;
    else if (N[1] == N[2] and N[2] == N[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string s;
  cin >> s;
  string result;
  const int64_t L = static_cast<int64_t>(s.length());
  for (int64_t i = 0; i < L; ++i) {
    const char ch = s.c_str()[i];
    if (ch == '0') {
      result.append("0");
    } else if (ch == '1') {
      result.append("1");
    } else {
      if (result.length() > 0) {
        result.pop_back();
      }
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 998244353, INF = 1e16;


template <std::int_fast64_t Modulus>
class modint
{
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept
	{
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept
	{
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept
	{
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept
	{
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept
	{
		a += rhs.a;
		if (a >= Modulus)
		{
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept
	{
		if (a < rhs.a)
		{
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept
	{
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept
	{
		u64 exp = Modulus - 2;
		while (exp)
		{
			if (exp % 2)
			{
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
typedef modint<MOD> ModInt;

lint N, S;
lint arr[3000];
ModInt dp[3001][3001];
int main() {
	cin >> N >> S;
	REP(i, N) {
		cin >> arr[i];
	}
	dp[0][0] = 1;
	REP(i, N) {
		REP(j, S + 1) {
			if (j + arr[i] <= S) dp[i + 1][j + arr[i]] += dp[i][j];
			dp[i + 1][j] += dp[i][j] * 2;
		}
	}
	cout << dp[N][S].a << endl;
}


Measured memory_bytes: 73952
'use strict';
function main(input) {
  const args = input.split('\n'),
        N = parseInt(args[0]),
        H = args[1].split(' ');
  for (let i = N-2; i >= 0; --i) {
    let difference = parseInt(H[i+1]) - parseInt(H[i]);
    if (difference === -1) {
      H[i] = (parseInt(H[i]) - 1).toString();
    } else if (difference < -1) {
      console.log('No');
      return;
    }
  }
  console.log('Yes');
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define MOD 1000000007
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)

using namespace std;

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

	ll n; cin >> n;
	ll ans = 0;

	if (1 <= n and n <= 9) ans = n;

	else if (10 <= n and n <= 99) ans = 9;

	else if (100 <= n and n <= 999) ans = n - 90;

	else if (1000 <= n and n <= 9999) ans = 909;

	else if (10000 <= n and n <= 99999) ans = n - 9090;

	else ans = 90909;

	cout << ans;

	return 0;
}

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

using namespace std;

int main()
{
    string s;
    string n="es";
    string m="s";
    cin>>s;
    if(s[s.length()-1]=='s'){
        cout<<s.append(n);
    }
    
    else{
        cout<<s.append(m);
    }
}


Measured memory_bytes: 3632
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int T = scanner.nextInt();
    
    
    int sumA = A;
    int sumB = 0;
    
    while(sumA <= T){
    
      sumA += A;
      sumB += B;
    }
    
    System.out.println(sumB);
    
  }
}


Measured memory_bytes: 21716
def solve():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = list(input())
    
    ans = 0
    for i in range(K):
        if T[i] == 'r':
            ans += P
        elif T[i] == 's':
            ans += R
        else:
            ans += S
    for i in range(K, N):
        if T[i-K] != T[i]:
            if T[i] == 'r':
                ans += P
            elif T[i] == 's':
                ans += R
            else:
                ans += S
        else:
            T[i] = 'n'
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){
    int a, b;
    cin >> a >> b;
    cout << (b<a ? a-1: a) fin;
  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;




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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int dec = 0;
		for(int i = 0;i<s.length();i++) {
			for(int k = i+1;k<s.length();k++) {
				if(s.charAt(i) == s.charAt(k)) {
					dec = 1;
					break;
				}
			}
		}
		if(dec == 1) {
			System.out.println("no");
		}else {
			System.out.println("yes");
		}
	}

}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-


def main():
    """Function."""
    d = int(input())

    if d == 25:
        print("Christmas")
    elif d == 24:
        print("Christmas Eve")
    elif d == 23:
        print("Christmas Eve Eve")
    elif d == 22:
        print("Christmas Eve Eve Eve")

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

//Binary Indexed Tree
//1-indexed
template<class T> class BIT {
private:
	vector<T>arr;
	const int n;

public:
	//初期化
	BIT(int _n) :arr(_n + 1, 0), n(_n) {}

	//１番目からi番目までの和
	T sum(int i) {
		T s = 0;
		while (i > 0) {
			s += arr[i];
			i -= i & (-i); //LSB減算
		}
		return s;
	}

	//[i, j]の要素の総和
	T sum(int i, int j) {
		T ret_i = sum(i - 1);
		T ret_j = sum(j);
		return ret_j - ret_i;
	}

	//i番目に要素xを追加
	void add(int i, T x) {
		while (i <= n) {
			arr[i] += x;
			i += i & (-i);
		}
	}
};

int main() {
	init();

	int N, Q; cin >> N >> Q;
	vector<int>A(N);
	BIT<int>bit(N);
	//(r,l)
	vector<tuple<int, int, int>>query(Q);
	vector<int>appear(N, -1);
	vector<int>ans(Q);
	rep(i, 0, N)cin >> A[i];
	rep(i, 0, Q) {
		int a, b; cin >> a >> b;
		query[i] = { b,a ,i };
	}
	sort(all(query));
	int now = -1;
	rep(i, 0, Q) {
		int l, r, j;
		tie(r, l, j) = query[i];
		while (now + 1 < r) {
			now++;
			int& index = appear[A[now] - 1];
			if (index == -1) {
				index = now;
				bit.add(now + 1, 1);
			}
			else {
				bit.add(index + 1, -1);
				index = now;
				bit.add(now + 1, 1);
			}
		}
		ans[j] = bit.sum(l, r);
	}
	rep(i,0,Q)cout<<ans[i]<<"\n";

	return 0;
}

Measured memory_bytes: 17380
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
typedef  pair<int,int> P;

int main()
{
string s,t;
cin>>s>>t;
int ans=0;
for(int i=0;i<=s.size()-t.size();i++)
{
int k=0;
for(int j=0;j<t.size();j++)
{
if(t[j]==s[j+i])k++;
}
ans=max(ans,k);
}

cout <<t.size()-ans;
}


Measured memory_bytes: 3628
N = int(input())
test_list = list(map(int, input().split()))
sorted_list = [idx+1 for idx in range(N)]
cnt = 0
for idx in range(N):
  if test_list[idx] != sorted_list[idx]:
    cnt += 1
if cnt <= 2:
  print('YES')
else:
  print('NO')


Measured memory_bytes: 3060
/**
 *  
 *  
 * */
#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;
    vector<double> v(N);
    rep(i, N) {
        cin >> v[i];
    }
    rep(i, N-1) {
        sort( v.begin(), v.end() );
        v[i] = (v[i] + v[i + 1])/2;
        v[i + 1] = 0;
    }
    sort( v.begin() , v.end() );
    reverse(v.begin(), v.end());
    cout << v.at(0);
return 0;}
/*compile
g++ code.cpp
./a.out
run*/

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

template <int MOD>
struct ModInt {
    int val;
    // constructor
    ModInt(ll v = 0) : val(int(v % MOD)) {
        if (val < 0) val += MOD;
    };
    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }
    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(ll n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }
    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = int(ll(val) * x.val % MOD);
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }
    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};
using mint=ModInt<int(1e9+7)>;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin>>n>>m;
    vector<mint> fac(m+1);
    fac[0]=1;
    for(int i=1;i<=m;i++) fac[i]=fac[i-1]*i;
    mint ans=0;
    auto C=[&](int a,int b){
        return fac[a]/fac[b]/fac[a-b];
    };
    for(int i=0;i<=n;i++){
        auto res=C(n,i)*C(m-i,n-i)*fac[n-i];
        if(i&1) ans-=res;
        else ans+=res;
    }
    cout<<ans*C(m,n)*fac[n];
    return 0;
}



Measured memory_bytes: 5340
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <cmath>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    ll N;
    cin >> N;

    vector<ll> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];

    ll ans = 0;
    for(int i = 0; i < N; i++){
        ll likeId = v[i];
        if (v[likeId - 1] == i + 1){
            ans ++;
        }
    }

    cout << ans / 2 << endl;
    

}

Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
int n,con;
con=0;
while(scanf(" %d",&n)!=EOF)
{
for(int a=0;a<10;a++)
for(int b=0;b<10;b++)
for(int c=0;c<10;c++)
for(int d=0;d<10;d++)
if(a+b+c+d==n)con++;
printf("%d\n",con);
con=0;
}
return 0;

}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

int a[575][575];

signed main() {
  INIT;

	VAR(int, H, W);
	REP(hi, H) {
		REP(wi, W) {
			cin >> a[hi][wi];
			a[hi][wi] %= 2;
		}
	}

	vector< string > ans;
	REP(hi, H) {
		REP(wi, W) {
			if (wi == W - 1) {
				if (hi < H - 1) {
					if (a[hi][wi] % 2 == 1) {
						string t = to_string(hi + 1) + " ";
						t += to_string(wi + 1) + " ";
						t += to_string(hi + 2) + " ";
						t += to_string(wi + 1);
						ans.push_back(t);
						a[hi + 1][wi]++;
					}
				}
			} else {
				if (a[hi][wi] == 1) {
					string t = to_string(hi + 1) + " ";
					t += to_string(wi + 1) + " ";
					t += to_string(hi + 1) + " ";
					t += to_string(wi + 2);
					ans.push_back(t);
					a[hi][wi + 1]++;
				}
			}
		}
	}

	OUT(ans.size())BR;
	EACH(ai, ans) {
		OUT(ai)BR;
	}

  return 0;
}


Measured memory_bytes: 13172
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n; cin>>n;
  vector<bool> s(13),h(13),c(13),d(13);
  rep(i,0,n){
    char q;
    int a;
    cin>>q>>a;
    if(q=='S') s[a-1]=true;
    if(q=='H') h[a-1]=true;
    if(q=='C') c[a-1]=true;
    if(q=='D') d[a-1]=true;
  }
  rep(i,0,13) if(!s[i]) co("S"<<" "<<i+1);
  rep(i,0,13) if(!h[i]) co("H"<<" "<<i+1);
  rep(i,0,13) if(!c[i]) co("C"<<" "<<i+1);
  rep(i,0,13) if(!d[i]) co("D"<<" "<<i+1);
  return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>
#include <math.h>
 
#define ELEMENT_CNT_MIN 1
#define ELEMENT_CNT_MAX 1000000
#define ELEMENT_MIN 0
#define ELEMENT_MAX 1000000000
#define SHELL_SROT_CNT_MIN 1
#define SHELL_SROT_CNT_MAX 100

void shell_sort(int *p_arr, int size);
int insertion_srot(int *p_arr, int size, int interval);
void put_arr(int *p_arr, int size);
int get_int_sequence(int *p_num, int min, int max, int size);
int get_int(int *p_num, int min, int max);
int judge_constraint(int test_num, int min, int max);

 
int main(void){
     
    int element_num;
    int element[ELEMENT_CNT_MAX];
     
    if(get_int(&element_num, ELEMENT_CNT_MIN, ELEMENT_CNT_MAX) == -1)
    {
        return -1;
    }
     
    if(get_int_sequence(&element[0], ELEMENT_MIN, ELEMENT_MAX, element_num) == -1)
    {
        return -1;
    }
    
    shell_sort(&element[0], element_num);
    
    put_arr(&element[0], element_num);
    
    return 0;
}
 
int insertion_srot(int *p_arr, int size, int interval)
{
    int cnt = 0;    /* calculation amount */
    int i;
    int j;
    int locator;
    
    for(i = interval; i < size; i++)
    {
        locator = p_arr[i];
        j = i - interval;
        while(j >= 0 && p_arr[j] > locator)
        {
            p_arr[j + interval] = p_arr[j];
            j = j - interval;
            cnt++;
        }
        p_arr[j + interval] = locator;
    }
    
    return cnt;
}

void shell_sort(int *p_arr, int size)
{
   int cnt = 0;
   int interval = 1;    /* (pow(3, 0) - 1) / 2 == 0 */
   int i;
   int shell_sort_cnt = SHELL_SROT_CNT_MIN;
   int G[SHELL_SROT_CNT_MAX];
   
  for(i = shell_sort_cnt ;i <= SHELL_SROT_CNT_MAX; i++)
  {
      interval =  (int)((pow(3, i) - 1) / 2);
      if(interval > size)
      {
          shell_sort_cnt = i - 1;
          printf("%d\n",shell_sort_cnt);
          break;
      }
      G[i - 1] = interval;
  }
   
   
   for(i = shell_sort_cnt;;i--)
   {
       cnt += insertion_srot(p_arr, size, G[i - 1]);
       printf("%d ", G[i - 1]);
       if(G[i - 1] <= 1)
       {
           printf("\n");
           break;
       }
   }
   
   printf("%d\n", cnt);
   
   return;
}
 
void put_arr(int *p_arr, int size)
{
    int i;
     
    for(i = 0; i < size; i++)
    {
        printf("%d\n", p_arr[i]);
    }
    
    return;
}
 
int get_int_sequence(int *p_num, int min, int max, int size)
{
    int i;
     
    for(i = 0; i < size; i++)
    {
        if(get_int(&p_num[i], min, max) == -1)
        {
            return -1;
        }
    }
     
    return 0;
}
 
int get_int(int *p_num, int min, int max)
{
    scanf("%d%*c", p_num);
     
    if(judge_constraint(*p_num, min, max) == -1)
    {
        return -1;
    }
     
    return 0;
}
int judge_constraint(int test_num, int min, int max)
{
    if(test_num < min || test_num > max)
    {
        return -1;
    }
     
    return 0;
}

Measured memory_bytes: 5756
def CountingSort(a, b, k, n)
	c = []
	0.upto(k) do |i|
		c[i] = 0
	end

	1.upto(n) do |j|
		c[a[j]] += 1
	end

	1.upto(k) do |i|
		c[i] = c[i] + c[i-1]
	end

	n.downto(1) do |j|
		b[c[a[j]]] = a[j]
		c[a[j]] -= 1
	end
end

n = gets.to_i
a = gets.split.map &:to_i
a.unshift(0)
b = []
CountingSort(a, b, 10001, n)
b.shift
puts b.join(" ")

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

typedef long long ll;


int main(){
    ll a,b,c,x,y;
    ll ans = 5000 * 100000 * 2;
    cin >> a >> b >> c >> x >> y;

    // ABピザをiまい買う
    for(ll i = 0; i /2 <= x || i / 2 <= y; i+=2 ){
        ll tmpans = c * i;

        // 残りの買う量
        ll tmp_a = x - i/2;
        ll tmp_b = y - i/2;
        // 残りが必要なら買う
        if(tmp_a >= 0) tmpans += a * tmp_a;
        if(tmp_b >= 0) tmpans += b * tmp_b;

        if(tmpans < ans) ans = tmpans;

    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    int N,K;
    cin >> N >> K;
    
    int p = 0;
    double P[N+1];
    P[0] = 0;
    
    for(int i=1;i<=N;i++){
        cin >> p;
        P[i] = P[i-1]+(double)(1+p)/2;
    }
    
    double ans = 0;
    for(int i=K;i<=N;i++){
        ans = max(ans,P[i]-P[i-K]);
    }
    
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}



Measured memory_bytes: 1920
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
      if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= i;
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

int main(){
  int L, R, d;
  std::cin >> L >> R >> d;
  int ans = R/d - (L-1)/d;
  std::cout << ans << std::endl;
  return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e9

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1000000000+7;
const int MAX_N=1000;

int dp[1<<26];

int main(){
	string s;
	cin>>s;
	int n=s.size();
	int a[n+1];
	a[0]=0;
	a[1]=0|(1<<(s[0]-'a'));
	for(int i=2;i<=n;i++){
		a[i]=a[i-1]^(1<<(s[i-1]-'a'));
	}

	int opt[n+1];
	fill(opt,opt+n+1,INT_MAX);
	opt[0]=0;

	fill(dp,dp+(1<<26),INT_MAX);
	dp[a[0]]=0;

	int X[27];
	X[0]=0;
	for(int i=1;i<27;i++){
		X[i]=1<<(i-1);
	}

	for(int i=1;i<=n;i++){
		int minx=INT_MAX;
		for(int j=0;j<27;j++){
			minx=min(minx,dp[a[i]^X[j]]);
		}
		opt[i]=minx+1;

		dp[a[i]]=min(dp[a[i]],opt[i]);
	}

	cout<<opt[n]<<endl;
	return 0;
}

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

int main(){
    int N,u,v;
    cin >> N >> u >> v;
    u--; v--;
    G graph(N);
    rp(i,N-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> dis_t(N,10000000),dis_a(N,10000000);
    queue<P> que_t,que_a;
    que_t.push(make_pair(u,0)); que_a.push(make_pair(v,0));
    while(!que_t.empty()){
        P p=que_t.front(); que_t.pop();
        if(dis_t[p.first]<=p.second) continue;
        dis_t[p.first]=p.second;
        for(auto nxt:graph[p.first]){
            que_t.push(make_pair(nxt,p.second+1));
        }
    }
    while(!que_a.empty()){
        P p=que_a.front(); que_a.pop();
        if(dis_a[p.first]<=p.second) continue;
        dis_a[p.first]=p.second;
        for(auto nxt:graph[p.first]){
            que_a.push(make_pair(nxt,p.second+1));
        }
    }
    int ans=0;
    rp(i,N){
        if(dis_t[i]<dis_a[i]) ans=max(ans,dis_a[i]);
    }
    cout << ans-1 << endl;
    return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	if (N % 1000 == 0) print(0);
	else print(1000 - N % 1000);
}

Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, 0, n)

const int inf = 999999999;
const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	cin.tie(0);
	int N, K;
	cin >> N >> K;

	ll ans = 0;
	ll num1, num2;
	num1 = N / K;

	// Kが奇数の場合
	if (K % 2 == 1) {		
		ans = pow(num1, 3);
	}
	// Kが偶数の場合
	else {
		num2 = (N + K / 2) / K;
		ans = pow(num1, 3) + pow(num2, 3);
	}
	cout << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <stdio.h>
int d[300005];

int check1(int s);
int check2(int s,int N);

int main(void) {
	int N,i,f;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&d[i]);
	}
	f=check1(N-1);
	if(f==0){printf("no\n");return 0;}
	f=check2(0,N-1);
	if(f==0){printf("no\n");return 0;}
	else {printf("yes\n");}
	return 0;
}

int check1(int s){
	int i,f;
//	printf("%d\n",d[s]);
	if(s==0){return 1;}
	for(i=s-1;i>=0;i--){
		if(d[i]>=10*(s-i)){
			f=check1(i);
			if(f==0){return 0;}else{return 1;}
		}
	}
	return 0;
}

int check2(int s,int N){
	int i,f;
//	printf("%d\n",d[s]);
	if(s==N){return 1;}
	for(i=s+1;i<=N;i++){
		if(d[i]>=10*(i-s)){
			f=check2(i,N);
			if(f==0){return 0;}else{return 1;}
		}
	}
	return 0;
}



Measured memory_bytes: 7528
import numpy as np
n, k = map(int,input().split())
a = np.array(input().split(),dtype=int)
n1 = [0 for i in range(40)]
g0 = [0 for i in range(40)]
g1 = [0 for i in range(40)]
ss = [0 for i in range(40)]
t2 = [1 for i in range(40)]

for i in range(40):
    n1[i] = np.count_nonzero(a&1)
    a >>= 1
    if i > 0:
        t2[i] = t2[i-1]*2
    g0[i] = n1[i]*t2[i]
    if n1[i] < n-n1[i]:
        g1[i] = (n-n1[i])*t2[i]
        ss[i] = ss[i-1]+g1[i]
    else:
        ss[i] = ss[i-1]+g0[i]


def DFS(ni,ki,sm):
    if ni == 0:
        if ki == 0:
            return sm+g0[0]
        else:
            return sm+ss[0]
    else:
        if g1[ni] == 0 or ki//t2[ni] == 0:
            return DFS(ni-1,ki,sm+g0[ni])
        elif ki//t2[ni] > 1:
            return sm+ss[ni]
        else:
            return max(sm+ss[ni-1],DFS(ni-1,ki-t2[ni],sm+g1[ni]))

ma = DFS(39,k,0)
print(ma)


Measured memory_bytes: 26016
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

public class Main{
	int INF = 1 << 24;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			String [] s = new String[n];
			for(int i = 0; i < n; i++){
				s[i] = sc.next();
			}
			ArrayList<String> list = new ArrayList<String>();
			for(int i = 0; i < n; i++){
				boolean flg = false;
				for(int j = 0; j < n; j++){
					if(i == j) continue;
					if(s[j].matches(".*" + s[i] + ".*")){
						flg = true;
					}
				}
				if(! flg){
					list.add(s[i]);
				}
			}
			
			n = list.size();
			int [][] pass = new int[n][n];
			for(int i = 0; i <n; i++){
				for(int j = 0; j < n; j++){
					if(i == j) continue;
					int len = list.get(j).length();
					for(int k = len; k >=0 ; k--){
						String str = list.get(j).substring(0,k);
						if(list.get(i).endsWith(str)){
							pass[i][j] = len - k;
							break;
						}
					}
					
				}
			}
			
			int [][] dp = new int[n][1 << n];
			for(int i = 0; i < n; i++){
				Arrays.fill(dp[i], INF);
				dp[i][1 << i] = list.get(i).length();
			}
			
			for(int i = 0; i < (1 << n); i++){
				for(int j = 0; j < n; j++){
					if(dp[j][i] == INF) continue;
					for(int k = 0; k < n; k++){
						if((i & (1 << k)) > 0) continue;
						int next = i | (1 << k);
						int value = dp[j][i] + pass[j][k];
						dp[k][next] = Math.min(dp[k][next], value);
					}
				}
			}
			int ans = INF;
			for(int i = 0; i < n; i++){
				ans = Math.min(ans, dp[i][(1 << n) - 1]);
			}
			System.out.println(ans);
		}
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

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

char a[100005];
int x=0,y=0,ans=0;

int main()
{
    scanf("%s",a);
    int mm=strlen(a);
    for (int i=0;i<=mm;i++)
        if (x==y)
        {
            x++;
            if(a[i]=='p')
                ans--;
        } 
        else
        {
            y++;
            if(a[i]=='g')
                ans++;
        }
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;
typedef long long ll;

// #define DEBUG

vector<vector<int>> combination(int n, int k)
{
    vector<vector<int>> combination_for_return;
    if (k == 0)
        ;
    else if (k == 1)
    {
        for (int i = 0; i < n; i++)
        {
            vector<int> x = {i};
            combination_for_return.push_back(x);
        }
    }

    else
    {
        for (int i = k - 1; i < n; i++)
        {
            for (auto x : combination(i, k - 1))
            {
                x.push_back(i);
                combination_for_return.push_back(x);
            }
        }
    }
    return combination_for_return;
}

void enumerate_comnination(vector<int> x){
    ll s = 0;
    for (auto y : x)
        s += pow(2, y);
    cout << s << ":";
    for (auto y : x)
        cout << " " << y;
    cout << endl;
}

main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, k, m;
    cin >> n >> k;
    m = 0;
    for (auto x : combination(n, k))
    {
        enumerate_comnination(x);
    }
    return 0;
}



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

int main() {
  int N;
  cin>>N;
  vector<int> M(N);
  for(int i=0;i<N;i++){
    cin>>M.at(i);
  }
  sort(M.begin(),M.end());
  M.push_back(10000);
  reverse(M.begin(),M.end());
  
  int s=0;
  for(int i=1;i<=N;i++){
    if(M.at(i)<M.at(i-1)){
      s+=1;
    }
  }
  cout<<s<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

int main()
{
  long long a, b, n;
  cin >> n >> a >> b;
  if ((b - a) % 2 == 0) {
    cout << (b - a) / 2 << endl;
  } else {
    long long dist = min(a - 1, n - b);
    cout << dist + 1 + (b - a) / 2 << endl;
  }
  return 0;
}


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

int main(){
	int X,A,B,Y,ANS;
	
	cin >> X;
	cin >> A;
	cin >> B;
	
	Y = (X-A)/B;
	
	ANS = X - A - Y*B;
	
	cout << ANS;
	return 0;
}

Measured memory_bytes: 256