akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

//solution classes here

public class Main {

    //main solution here

    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int n = sc.nextInt();
        int fh = (n/500)*1000;
        int f = 5*((n-500*(fh/1000))/5);
        out.println(fh+f);

        out.flush();
        out.close();
    }

    //solution functions here


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

/* *****************************************************************************************************************************
 * I'M NOT IN DANGER, I'M THE DANGER!!!
 * *****************************************************************************************************************************
 */

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

#define ll              long long int
#define pb              push_back
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fast_io         ios_base::sync_with_stdio(false); cin.tie(NULL);


int main(){
    fast_io;
    
    ll n, k;
    cin >> n >> k;
    if(n == 0){
    	cout<<"0\n";
    	return 0;
    }

    vector<ll> v(n);

    for(ll i=0; i<n; i++){
        cin >> v[i];
    }

    vector<vector<ll>> dp(n, vector<ll>(k+1, 0));
    
    // base case
    for(ll j=0; j<=k and j<=v[0]; j++){
        dp[0][j] = 1;
    }

    for(ll i=1; i<n; i++){
        for(ll j=0; j<=k; j++){
            if(j == 0){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = dp[i][j-1] + dp[i-1][j];
                if((j-v[i]-1) >=0){
                    dp[i][j] -= dp[i-1][j-v[i]-1];
                }
            }

            dp[i][j] = (dp[i][j] % mod);
            dp[i][j] += mod;
            dp[i][j] = (dp[i][j] % mod);
        }
    }

    cout<<dp[n-1][k]<<"\n";
    
	return 0;
}



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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, a[100010], ma, cou[2];
int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
		ma = max(ma, a[i]);
	}
	for(int i=0;i<n;i++){
		if(ma==a[i]){
			cou[0]++;
		}else if(ma==a[i]+1){
			cou[1]++;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	if(cou[1]==0){
		if(n>=ma*2||ma==n-1){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else{
		if(cou[0]>=2*(ma-cou[1])&&cou[1]<=ma-1){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
    using namespace std;
    #define PAIN___ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define ll long long int
    #define fi first
    #define se second
    #define pb push_back
    #define pii pair < int , int >
    #define mp make_pair
    #define vec vector < ll >
    #define vecp vector < pii  >
    #define forl(i,q1,n,q2) for(ll i=q1;i<q2;i++)
    #define null NULL
    #define mm 1000005


    int main()
    {
        PAIN___;
        ll t;
        t=1;
        while(t--)
        {
            ll n,k;
            cin>>n>>k;
            ll a[n],sum[n+1];
            forl(i,0,n,n)cin>>a[i];
            sum[0]=0;
            sum[1]=a[0];
            forl(i,1,n,n+1)
            {
             sum[i+1]=a[i]+sum[i];
            }
            ll cnt=0;
            forl(i,0,n,n+1){if(sum[i]<=k)cnt++;}
            cout<<cnt<<endl;

    }
    }



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

int main()
{
    ll t;cin>>t;
    unordered_map <string,ll> mp;
    for(ll i=0;i<t;i++)
    {
        string s;
        cin>>s;
        mp[s]++;


    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

int N, M;
struct wordnum {
    string word;
    int num;
};
vector<wordnum> X;


void sortstr(string s, int a)
{
    for (wordnum& x : X) {
        if (x.word == s) {
            x.num += a;
            // cout << x.word << " " << x.num << endl;
            return;
        }
    }
    X.push_back({s, a});
    // cout << s << " " << a << endl;
    return;
}


int main()
{
    cin >> N;
    string s;
    for (int i = 0; i < N; i++) {
        cin >> s;
        sortstr(s, 1);
    }

    cin >> M;
    for (int i = 0; i < M; i++) {
        cin >> s;
        sortstr(s, -1);
    }

    int max = 0;
    for (wordnum x : X) {
        // cout << x.word << " " << x.num << endl;
        if (x.num > max) {
            max = x.num;
        }
    }

    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int n = sc.nextInt();
        int[] lengths = new int[n];
        for (int i = 0; i < n; i++) {
            lengths[i] = sc.nextInt();
        }
        
        int[][] table = new int[r][c];
        int k = 1;
        int l = 0;
        
        for (int i = 0; i < r; i++) {
            if (i % 2 == 0) {
                for (int j = 0; j < c; j++) {
                    table[i][j] = k;
                    l++;
                    if (l == lengths[k - 1]) {
                        k++;
                        l = 0;
                    }
                }
            } else {
                for (int j = c - 1; j >= 0; j--) {
                    table[i][j] = k;
                    l++;
                    if (l == lengths[k - 1]) {
                        k++;
                        l = 0;
                    }
                }
            }
        }
        
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(table[i][j]);
                if (j != c - 1) {
                    System.out.print(" ");
                } else {
                    System.out.println("");
                }
            }
        }
    }
}


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

using namespace std;

int arr[55];

int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", arr + i);
    sort(arr, arr + n);
    long double res = arr[0];
    for(int i=1; i<n; i++){
        res = (res + arr[i])/2;
    }
    printf("%.6Lf\n", res);
    return 0;
}


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

const int N = 100005;

int n;
string s;
int sz[N];
vector < pair<int,int> > ed;
vector <int> g[N];

void add(int u, int v) {
	//cerr << u << ' ' << v << endl;
	ed.push_back({u, v});
	g[u].push_back(v);
	g[v].push_back(u);
}

void dfs(int u, int p = -1) {
	sz[u] = 1;
	for (int v : g[u]) if (v != p) {
		dfs(v, u);
		sz[u] += sz[v];
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> s;
	n = s.size();
	s = '0' + s;
	
	if (s[1] != '1' || s[n] != '0') {
		return cout << -1 << endl, 0;
	}
	
	for (int i = 1; i <= n - 1; ++i) {
		if (s[i] != s[n - i]) {
			return cout << -1 << endl, 0;
		}
	}
	
	vector <int> pos;
	for (int i = 1; i <= n / 2; ++i) if (s[i] == '1') {
		pos.push_back(i);
	}
	
	int cur = 1;
	for (int i = 1; i < pos.size(); ++i) {
		int nxt = cur + pos[i] - pos[i - 1];
		for (int j = cur; j < nxt; ++j) {
			add(j, nxt);
		}
		cur = nxt;
	}
	
	assert(cur <= n - 1);
	add(cur, cur + 1);
	++cur;
	
	for (int i = cur + 1; i <= n; ++i) {
		add(cur, i);
	}
	
	dfs(1);
	string t = string(n + 1, '0');
	for (int i = 1; i <= n; ++i) {
		if (sz[i] < n) t[sz[i]] = t[n - sz[i]] = '1';
	}
	//cerr << s << ' ' << t << endl;
	
	if (s != t) {
		return cout << -1 << endl, 0;
	}
	
	for (auto e : ed) {
		cout << e.first << ' ' << e.second << endl;
	}
}


Measured memory_bytes: 11748
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll a;
  cin >> a;

  ll ans = a + a * a + a * a * a;
  cout << ans << endl;

  return 0;
}


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

int a[1000];

int main (){
    int n,m,x;
    scanf("%d %d %d",&n,&m,&x);
    memset(a,0,sizeof(a));
    for(int i=1;i<=m;i++){
        int val;scanf("%d",&val);
        a[val]=1;
    }
    int ans1=0,ans2=0;
    for(int i=x+1;i<=n;i++) ans1+=a[i];
    for(int i=0;i<x;i++) ans2+=a[i];
    cout<<min(ans1,ans2)<<endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = list(input())

ans = []
for i in range(len(s)):
    if s[i] == '0':
        ans.append('0')
    if s[i] == '1':
        ans.append('1')
    if len(ans) >= 1 and s[i] == 'B':
        ans.pop()
print(''.join(ans))


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
using namespace std;
 

int main(){
    int n;
    cin>>n;
    string s,ans="";
    cin>>s;
    int si=s.size();
    for(int i=0;i<si;i++){
        if((s[i]-'@')+n>26){
            ans+=(s[i]-(26-n));
        }
        else ans+=(s[i]+n);
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define PI 3.141592653589
double th = 60*PI/180;
void fanction(int n,double p1[],double p2[]){
  double s[2],u[2],t[2];

  s[0]=(2*p1[0]+p2[0])/3;
  s[1]=(2*p1[1]+p2[1])/3;
  t[0]=(p1[0]+2*p2[0])/3;
  t[1]=(p1[1]+2*p2[1])/3;
  u[0]=(t[0]-s[0])*cos(th)-(t[1]-s[1])*sin(th)+s[0];
  u[1]=(t[0]-s[0])*sin(th)+(t[1]-s[1])*cos(th)+s[1];

  if(n==0){
   printf("%lf %lf\n",p2[0],p2[1]);
    return;
  }
  if(n==1){

    printf("%lf %lf\n",s[0],s[1]);
    printf("%lf %lf\n",u[0],u[1]);
    printf("%lf %lf\n",t[0],t[1]);
    printf("%lf %lf\n",p2[0],p2[1]);

    return;
  }

  fanction(n-1,p1,s);

 fanction(n-1,s,u);

  fanction(n-1,u,t);

  fanction(n-1,t,p2);
}

int main(void){
  int n;
  double p1[2],p2[2];
  scanf("%d",&n);
  p1[0]=0;
  p1[1]=0;
  p2[0]=100;
  p2[1]=0;
  printf("%lf %lf\n",p1[0],p1[1]);
  fanction(n,p1,p2);

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
    
  int n, x;

	long int max = -1000000000;
	long int min ;
	int i = 1;
	scanf("%d", &n);

	while (n--) {
		scanf("%d", &x);
		if (i == 1) {
			min = x;
			
		}
		if (i != 1) {
				if (max < x - min) {
					max = x - min;
				}
				if (min > x) {
					min = x;
				}
			
		}
		i++;
	}

    printf("%d\n",max);
    return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<typename T>
struct cumulative_sum {
    int n;
    T ZERO;
    std::vector<T> data;
    template<typename I> cumulative_sum(I begin, I end, T ZERO = T())
        : n(end - begin), ZERO(ZERO), data(n + 1, ZERO) {
        std::copy(begin, end, data.begin() + 1);
        for (int i = 0; i < n; i++) { data[i + 1] += data[i]; }
    }
    T get_sum(int l, int r) const {
        if (l >= r || l > n || r < 0) { return ZERO; }
        if (l < 0) { l = 0; }
        if (r > n) { r = n; }
        return data[r] - data[l];
    }
};

int N;
string S;
int a[220000];
signed main() {
    cin >> N >> S;
    rep(i, N) { a[i] = S[i] == '#'; }
    cumulative_sum<int> cs(a, a + N);
    int ans = LLONG_MAX;
    for (int i = 0; i <= N; i++) {
        chmin(ans, cs.get_sum(0, i) + (N - i) - cs.get_sum(i, N));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#include <string.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) ((a)>(0)?(a):-(a))
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
using namespace std;
int main(){
    int k,x,i;
    cin>>k>>x;
    rep(i,x-k+1,x+k)cout<<i<<" ";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    int K, S;
    int count = 0;
    cin >> K >> S;

    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= K; j++) {
            if ((S - i - j >= 0) && (K >= S - i - j)) {
                count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    // 文字列の入力
    String S = sc.next();

    String[] aList = S.split("");
    if(aList[2].equals(aList[3]) && aList[4].equals(aList[5])) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}


Measured memory_bytes: 21716
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000

int main() {
	int n, m;
	int x, y, z, l, r, mid, ans, s;
	bool v;
	vector<int>a;
	scanf("%d %d", &n, &m);
	f(i, 2 * n) {
		scanf("%d", &x);
		x %= m;
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	ans = 0;
	f(i, n) {
		x = (a[i] + a[(2 * n) - i - 1]) % m;
		ans = max(ans, x);
	}
	l = n;
	r = 2 * n;
	while ((l + 1) < r) {
		mid = (l + r) / 2;
		v = true;
		x = mid;
		y = mid - 1;
		while (x < (2 * n)) {
			z = a[x] + a[y];
			if (z < m)v = false;
			x++;
			y--;
		}
		if (v)r = mid;
		else l = mid;
	}
	s = 0;
	x = r;
	y = r - 1;
	while (x < (2 * n)) {
		z = (a[x] + a[y]) % m;
		s = max(z, s);
		x++;
		y--;
	}
	x = 0;
	while (x < y) {
		z = (a[x] + a[y]) % m;
		s = max(z, s);
		x++;
		y--;
	}
	ans = min(ans, s);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1400
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200005
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "



int main()
{
	ll n;
	ll ans = 0;
	cin >> n;
	if(n%2==0)
	{
		n/=10;
		ans+=n;
		while(n>=5)
		{
			n/=5;
			ans+=n;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include<cstdio>
#include<string>
#include <string.h>
#include<stdio.h>
using namespace std;

int main() {
	string W, T;
	int count = 0;
	cin >> W;

	for (int i = 0; i<W.size(); i++) {
		if ('A' <= W[i] && W[i] <= 'Z') {
			W[i] += 'a' - 'A';
		}
			
	}

	while (true) {
		cin >> T;
		if (T == "END_OF_TEXT") {
			break;
		}

		for (int i = 0; i<T.size(); i++) {
			if ('A' <= T[i] && T[i] <= 'Z') T[i] += 'a' - 'A';
		}

		if (W == T) {
			count++;
		}

		
	}

	cout << count << endl;

	return 0;
}




Measured memory_bytes: 3220
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int INF = 1e9 + 7;
int _;

int main() {
	INIT
	int k, n;
	cin >> k >> n;
	VI A(n);
	int ans = INF;
	rep (i, 0, n) {
		cin >> A[i];
	}
	rep (i, 0, n) {
		int d;
		if (!i) {
			d = min(A[0] + k - A[1], A[n - 1] - A[0]);
		} else if (i == n - 1) {
			d = min(k - A[i] + A[i] - 1, A[i] - A[0]);
		} else {
			d = min((k - A[i] + A[i - 1]), (A[i] + k - A[i + 1]));
		}
		if (d < ans) ans = d;
	}
	cout << ans << endl;

	return 0;
}
/*
rep (i, 0, n) {
		if (i) cout << ' ';
		cout << A[i];
	}
*/

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

int N, M, H;
int A[200000];
vector<int> L[20];
vector<int> V[20];  // 頂点番号
vector<int> G[200000 * 20];

map<vector<int>, bool> memo[20];
bool rec(const vector<int>& vs, int depth) {
  if (vs.size() <= 1) return true;
  if (depth == H - 1) return false;
  auto it = memo[depth].find(vs);
  if (it != memo[depth].end()) return it->second;
  
  int sum = 0;
  for (int from : vs) {
    sum += G[from].size();
  }
  
  for (int i = 0; i < vs.size(); ++i) {
    if (sum - G[vs[i]].size() > H - depth) continue;
    vector<int> nvs;
    for (int j = 0; j < vs.size(); ++j) {
      if (j == i) continue;
      int from = vs[j];
      for (int nv : G[from]) {
        nvs.push_back(nv);
      }
    }
    if (rec(nvs, depth + 1)) return memo[depth][vs] = true;
  }
  return memo[depth][vs] = false;
}

void create() {
  V[0] = {0};
  int nv = 1;
  for (int k = 1; k < H; ++k) {
    int ni = 0;
    for (int i = 1; i < L[k - 1].size(); ++i) {
      int l = L[k - 1][i - 1];
      int r = L[k - 1][i];
      int v = V[k - 1][i - 1];
      while (ni < L[k].size() && L[k][ni] < r) {
        G[v].push_back(nv);
        V[k].push_back(nv);
        ++nv;
        ++ni;
      }
    }
  }
}

void pre() {
  L[0] = {0, N};
  int s = M;
  int k = 1;
  while (true) {
    L[k].push_back(0);
    for (int i = 1; i < N; ++i) {
      if (A[i] - A[i - 1] > s) {
        L[k].push_back(i);
      }
    }
    L[k].push_back(N);
    if (s == 0) break;
    s /= 2;
    ++k;
  }
  H = k + 1;
}

int main() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i) cin >> A[i];
  pre();
  create();
  
  int P = V[1].size();
  for (int i = 1; i <= P; ++i) {
    vector<int> vs;
    for (int j = 1; j <= P; ++j) {
      if (j == i) continue;
      for (int v : G[j]) {
        vs.push_back(v);
      }
    }
    
    bool ans = rec(vs, 2);
    for (int z = L[1][i - 1]; z < L[1][i]; ++z) {
      cout << (ans ? "Possible" : "Impossible") << endl;
    }
  }
}

Measured memory_bytes: 128000
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

int main(){
  int a,b;
  cin>>a>>b;
  cout<<(a+b+1)/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int n ;
  scanf("%d",&n) ;

  int x ;
  int y ;

  for( x=1 ; x<=n ; x++ ){
    if( x % 3 == 0){
      printf(" %d", x) ;
    }else{
      y = x;
      while( y != 0 ){
        if( y % 10 == 3){
          printf(" %d",x) ;
          y = 0 ;
        }else{
          y = y / 10 ;
        }
      }
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 2028
n=int(input())
s=input()
w=[0]*n
e=[0]*n
for i in range(n):
  if s[i]=="W":
    w[i]+=1
  else:
    e[i]+=1
from itertools import accumulate
w=list(accumulate(w))
e=list(accumulate(e))
# print("w:",w)
# print("e:",e)
ans=10**18
for i in range(n):
  t=0
  if s[i]=="W":
    if i!=0:
      t+=w[i-1]
    t+=e[-1]-e[i]
  else:
    if i!=0:
      t+=w[i-1]
    t+=e[-1]-e[i]
  ans=min(t,ans)
print(ans)

Measured memory_bytes: 31140
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 3010
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,p,ans,inv[maxn],S[maxn][maxn];
int add(int x,int y)
{
	return (x+y)%p;
}
int sub(int x,int y)
{
	return (x-y+p)%p;
}
int mul(int x,int y)
{
	return 1ll*x*y%p;
}
int fpow(int x,int y,int P=p)
{
	int res=1;
	while(y)
	{
		if(y&1)
			res=1ll*res*x%P;
		x=1ll*x*x%P;
		y>>=1;
	}
	return res;
}
int main()
{
	read(n,p);
	inv[0]=inv[1]=1;
	for(int i=2;i<=n;i++)
		inv[i]=mul(p-p/i,inv[p%i]);
	S[0][0]=1;
	for(int i=1;i<=n+1;i++)
		for(int j=1;j<=i;j++)
			S[i][j]=add(mul(j,S[i-1][j]),S[i-1][j-1]);
	int a=1,b=fpow(2,n),inv2=(p+1)/2;
	for(int i=0;i<=n;i++)
	{
		int o=0;
		for(int j=0,k=1;j<=i;j++,k=mul(k,b))
			o=add(o,mul(S[i+1][j+1],k));
		if(i&1)ans=sub(ans,mul(mul(a,fpow(2,fpow(2,n-i,p-1))),o));
		else ans=add(ans,mul(mul(a,fpow(2,fpow(2,n-i,p-1))),o));
		a=mul(a,mul(inv[i+1],n-i));
		b=mul(b,inv2);
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 34304
#include<stdio.h>

int main(){
	int a, b;
	
	scanf("%d %d", &a, &b);
	
	if (a > b) {
		printf("a > b\n");
	} else if (a < b) {
		printf("a < b\n");
	} else
		printf("a == b\n");
	
	return 0;
}
	
	

Measured memory_bytes: 1800
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;
template<typename T> void test(vector<T> v){for(int i=0;i<v.size();i++){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

int main(){
    int n,l,r;
    while(cin>>n>>l>>r&&n&&l&&r){
        vector<int> v(n);
        rep(i,0,n)cin>>v[i];
        int ans=0;
        rep(i,l,r+1){
            bool flag=true;
            rep(j,0,n){
                if(i%v[j]==0){
                    flag=false;
                    if(j%2==0)ans++;
                    break;
                }
            }
            if(flag&&n%2==0)ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
} 


Measured memory_bytes: 3096
var
    h,w,i,j:longint;
    a:array[0..101,0..101] of char;
    b,c:array[0..101] of boolean;
    flag:boolean;
begin
    readln(h,w);
    for i:=1 to h do
        begin 
            for j:=1 to w do
                begin 
                    read(a[i,j]);
                    if a[i,j]='#' then 
                        begin 
                            b[i]:=true;
                            c[j]:=true;
                        end;
                end;
            readln;
        end;
    for i:=1 to h do    
        begin
            flag:=true;
            for j:=1 to w do
                if b[i] and c[j] then 
                    begin 
                        flag:=false;
                        write(a[i,j]);
                    end;
            if not flag then writeln;
        end;
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define LL long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const LL mod = 998244353;
bool mark[2][3010][3010];
LL memo[2][3010][3010];
int A[3010];
int n, s;
LL dp(int f, int p, int sum){
	if(sum == 0) return n - p + 1;
	if(p == n) return 0;
	LL& ans = memo[f][p][sum];
	if(mark[f][p][sum]) return ans;
	mark[f][p][sum] = true;
	ans = 0;
	if(!f) ans = dp(1, p, sum);
	(ans += dp(f, p+1, sum)) %= mod;
	if(f && sum - A[p] >= 0) (ans += dp(f, p+1, sum - A[p])) %= mod;
	return ans;
}
int main(){
	scanf("%d %d", &n, &s);
	for(int i = 0; i < n; i++) scanf("%d", &A[i]);
	printf("%lld\n", dp(0, 0, s));
	return 0;
}

Measured memory_bytes: 158080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<int,int>;
using Graph =vector<string>;
Graph field;
queue<P> q;

int main() {
  ll k;
  cin>>k;
  ll a=7%k;
  ll ans=1;
  while(a!=0){
    a=(10*a+7)%k;
    ans++;
    if(ans>k+1){
      ans=-1;
      break;
      }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3608
s = input()
q = int(input())
mae,usiro = [],[]

f = 0
for i in range(q):
    t = input().split()
    if t[0] == "1":
        if f % 2 == 0:
            f = 1
        else:
            f = 0
    elif t[0] == "2":
        if t[1] == "1":
            if f == 1:
                usiro.append(t[2])
            else:
                mae.append(t[2])
        elif t[1] == "2":
            if f == 1:
                mae.append(t[2])
            else:
                usiro.append(t[2])

mae = mae[::-1]
ans = "".join(mae)+s+"".join(usiro)
if f:
    print(ans[::-1])
else:
    print(ans)


Measured memory_bytes: 96184
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

int main(){
    int N;
    cin >> N;
    int B[N-1];
    rep(i,N-1) cin >> B[i];
    vector<int> v;
    rep(i,N){
        if(i==0){
            v.push_back(B[i]); 
        }
        else if(i==N-1){
            v.push_back(B[i-1]); 
        }
        else if(B[i]>=B[i-1]){
            v.push_back(B[i-1]); 
        }
        else{
            v.push_back(B[i]); 
        }
    }
    int ans =0;
    rep(i,N) ans += v[i];
    cout << ans << endl;
    return 0;
}



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

int main(){
    ll K, A, B;
    cin >> K >> A >> B;
    if (A >= B-1 || K <= A) cout << K+1 << endl;
    else cout << A + (K-A+1)/2*(B-A) + (K-A+1)%2 << endl;
    return 0;
}


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

int main()
{
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if((a <= c) && (c <= b)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return 0;
}

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

int main()
{
ll n ;
cin >> n ;
string s ;
cin >> s ;
ll q ;
cin >> q ;
vector<ll> k(q);
rep(i, q){
  cin >> k[i];
}
rep(i,q){
ll nummc=0,numm=0,numc=0,ans=0;
rep(j,k[i]){
  if(s[j]=='M')numm++;
  if(s[j]=='C'){numc++;nummc+=numm;}
}
rep(j,n-k[i]){
  if(s[j]=='D')ans+=nummc;
  if(s[j]=='M'){nummc-=numc;numm--;}
  if(s[j]=='C')numc--;
  if(s[j+k[i]]=='M')numm++;
  if(s[j+k[i]]=='C'){numc++;nummc+=numm;}
}
rep(j,k[i]){
  if(s[n-k[i]+j]=='D')ans+=nummc;
  if(s[n-k[i]+j]=='M'){nummc-=numc;numm--;}
  if(s[n-k[i]+j]=='C')numc--;
}
cout << ans << endl;
}
return 0;
}

Measured memory_bytes: 1540
#include<map>
#include<set>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define sz(a) ((int)(a).size())
#define vi vector<int>
#define pii pair<int,int>
#define R(a) scanf("%d",&a)
#define per(i,a,b) for(int i=a;i>=int(b);i--)
#define rep(i,a,b) for(int i=a;i<=int(b);i++)
#define rix(i,x) for(int i=last[x];i;i=pre[i])
ll pow(ll a,ll b,ll M){ll t=1;for(a%=M;b;b>>=1){if(b&1)t=t*a%M;a=a*a%M;}return t;}
const int N=1e5+5;
vector<pii>e[N];
int s[N],n,c;ll ans,p=-1;
int dfs(int x,int fa){
	s[x]=1;for(pii i:e[x]){
		int y=i.ft;if(y==fa)continue;
		dfs(y,x);s[x]+=s[y];
	}
	int fg=1,sz=n-1;for(pii i:e[x]){
		int y=i.ft;if(y==fa)continue;
		int t=min(s[y],n-s[y]);
		ans+=2LL*t*i.sd;
		if(t*2==n)p=i.sd;
		if(s[y]*2>=n)fg=0;
		sz-=s[y];
	}
	if(sz*2>=n)fg=0;
	if(fg)c=x;
}
int main(){
	cin>>n;rep(i,1,n-1){
		int x,y,c;
		R(x);R(y);R(c);
		e[x].pb(mp(y,c));
		e[y].pb(mp(x,c));
	}
	dfs(1,0);
	if(p>=0)ans-=p;else{
		int rem=1e9;
		for(pii i:e[c])
			rem=min(rem,i.sd);
		ans-=rem;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 14080
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 300005
#define mo 1000000007
using namespace std;

int n,i,j,k,f[2][3][3],ans;

int main(){
	int p=0,q=1;f[0][0][0]=1;
	for(char ch=getchar();ch=='0'||ch=='1'||ch=='?';ch=getchar()){
		p^=1,q^=1,memset(f[p],0,sizeof(f[p]));
		if (ch=='0'||ch=='?'){
			for(i=0;i<3;i++) for(j=0;j<3;j++) 
				(f[p][i][j?(3-j):1]+=f[q][i][j])%=mo;
		} 
		if (ch=='1'||ch=='?'){
			for(i=0;i<3;i++) for(j=0;j<3;j++)	
				(f[p][min(2,i+(j==0))][max(j-1,0)]+=f[q][i][j])%=mo;
		}
	}
	for(i=0;i<3;i++) for(j=0;j<3;j++) if (i>=2||j==0) (ans+=f[p][i][j])%=mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 1580
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <iomanip>
#define int long long
#define endl "\n";
#define debug(x) cout << #x << " is " << x << endl;
using namespace std;
int gcd(int a, int b) {
	if (!b) return a;
	return gcd(b, a % b);
}
void solve() {
	int a, b, c, k, ans = 0;
	cin >> a >> b >> c >> k;
	ans += min(a, k) - max(k - a - b, 0LL);
	cout << ans;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(15);
	int t;
	t = 1;
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(void)
{
  int n;
  cin>>n;
  int num[4][13]={0};
  
  for(int i=0;i<n;i++)
    {
      char x;
      cin>>x;
      int y;
      cin>>y;
      if(x=='S')num[0][y-1]++;
      else if(x=='H')num[1][y-1]++;
      else if(x=='C')num[2][y-1]++;
      else if(x=='D')num[3][y-1]++;
    }
  for(int i=0;i<4;i++)
    {
      for(int j=0;j<13;j++)
	{
	  
	  if(num[i][j]==0 && i==0)cout<<'S'<<" "<<j+1<<endl;
	  else if(num[i][j]==0 && i==1)cout<<'H'<<" "<<j+1<<endl;
	  else if(num[i][j]==0 && i==2)cout<<'C'<<" "<<j+1<<endl;
	  else if(num[i][j]==0 && i==3)cout<<'D'<<" "<<j+1<<endl;
	}
    }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

#define ll long long
#define ull unsigned long long
#define mem(Arr,x) memset(Arr,x,sizeof(Arr))

const int maxN=202000;
const int inf=2147483647;

int n;
ull X,Sum[maxN];

int main(){
	cin>>n>>X;
	for (int i=1;i<=n;i++){
		cin>>Sum[i];
		Sum[i]+=Sum[i-1];
	}

	ull Ans=Sum[n]*5+n*X;

	for (int K=1;K<n;K++){
		ull nowans=K*X;
		if (K*2>=n) nowans=nowans+5*Sum[n];
		else{
			nowans=nowans+5*(Sum[n]-Sum[n-2*K]);
			int lst=n-2*K;
			ull cost=7;
			while (lst>=K){
				nowans=nowans+cost*(Sum[lst]-Sum[lst-K]);
				cost+=2;lst-=K;
			}
			nowans=nowans+cost*Sum[lst];
		}
		Ans=min(Ans,nowans);
	}

	cout<<Ans+X*n<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <math.h>

using std::cin;
using std::cout;

int main(int argc, char const *argv[])
{
    long long n, a, b;
    cin >> n >> a >> b;
    if (a > b || (n == 1 && a < b))
    {
        cout << 0;
        return 0;
    }
    cout << (n-2)* (b - a) + 1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

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

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N, long long M, std::vector<long long> H, std::vector<long long> A, std::vector<long long> B)
{

  vector<vector<int>> adj(N);
  for (int i = 0; i < M; i++)
  {
    int u = A[i];
    int v = B[i];
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  int ret = 0;
  for (int i = 0; i < N; i++)
  {
    int cnt = 0;
    for (auto v : adj[i])
      if (H[v] >= H[i])
        cnt++;
    if (cnt == 0)
      ret++;
  }
  cout << ret << endl;
}

int main()
{
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &H[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++)
  {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, M, std::move(H), std::move(A), std::move(B));
  return 0;
}


Measured memory_bytes: 10500
s=input()
t=input()


def f(s):
    l=[]
    a="abcdefghijklmnopqrstuvwxyz"
    r=""
    for i in range(len(s)):
        if s[i] in l:
            for j in range(len(l)):
                if s[i]==l[j]:
                    r+=a[j]
        else:
            r+=a[len(l)]
            l.append(s[i])
    return r

if f(s)==f(t):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3820
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll k,x;
cin>>k>>x;
if(500*k>=x){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}
}










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

using namespace std;

class combination {
    vector<long long> inv;
    vector<long long> frac;
    vector<long long> frac_inv;
    int mod;

public:
    combination(int n, int m) {
        inv = vector<long long>(n + 1, 0);
        frac = vector<long long>(n + 1, 0);
        frac_inv = vector<long long>(n + 1, 0);
        mod = m;

        inv[1] = 1;
        frac[0] = frac[1] = 1;
        frac_inv[0] = frac_inv[1] = 1;
        for (int i = 2; i <= n; i++) {
            inv[i] = mod - (inv[mod % i] * (mod / i)) % mod;
            frac[i] = (frac[i - 1] * i) % mod;
            frac_inv[i] = (frac_inv[i - 1] * inv[i]) % mod;
        }
    }

    int calc(int n, int k) {
        return (frac[n] * frac_inv[k] % mod) * frac_inv[n - k] % mod;
    }
};

int main() {
    int k;
    string s;
    cin >> k >> s;

    int s_size = s.size();

    long long mod = 1000000007;
    combination nck(k + s_size, mod);

    vector<long long> pow25(k + 1, 1), pow26(k + 1, 1);
    for (int i = 1; i <= k; i++) {
        pow25[i] = (25 * pow25[i - 1]) % mod;
        pow26[i] = (26 * pow26[i - 1]) % mod;
    }

    long long res = 0;
    for (int i = 0; i <= k; i++) {
        long long p = (pow25[i] * pow26[k - i]) % mod;
        res = (res + nck.calc(s_size + i - 1, i) * p) % mod;
    }

    cout << res << endl;
}


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

const int INF = 1e+9;

int main(){
    int n, cnum;
    cin >> n >> cnum;
    int d[30][30];
    for(int i = 0; i < cnum; i++){
        for(int j = 0; j < cnum; j++){
            cin >> d[i][j];
        }
    }
    int cnt[3][30];
    //vector<int, vector<int>> cnt(3, vector<int>(cnum));
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            int temp;
            cin >> temp;
            cnt[(i+j) % 3][temp-1]++;
        }
    }
    int ans = INF;
    for(int c1 = 0; c1 < cnum; c1++){
        for(int c2 = 0; c2 < cnum; c2++){
            if(c1 == c2) continue;
            for(int c3 = 0; c3 < cnum; c3++){
                if(c1 == c3 || c2 == c3) continue;
                int temp = 0;
                for(int j = 0; j < cnum; j++){
                    temp += cnt[0][j] * d[j][c1];
                }
                for(int j = 0; j < cnum; j++){
                    temp += cnt[1][j] * d[j][c2];
                }
                for(int j = 0; j < cnum; j++){
                    temp += cnt[2][j] * d[j][c3];
                }
                ans = min(ans, temp);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    while (b <= a && k)
    {
        k--;
        b <<= 1;
    }

    while (c <= b && k)
    {
        k--;
        c <<= 1;
    }

    cout << ((a < b && b < c) ? "Yes" : "No") << '\n';
    return (0);
}


Measured memory_bytes: 3628
#include<cstdio>
#include<queue>
using namespace std;
int n,m,x,ans,tot[310];
bool vis[310];
queue<int> que[310];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			scanf("%d",&x);
			if (j==1) tot[x]++;
			que[i].push(x);
		}
	}
	int mx=0,j=0;
	for (int i=1;i<=m;i++)
		if (tot[i]>mx){ mx=tot[i]; j=i;}
	ans=mx; vis[j]=true;
	for (int k=1;k<m;k++){
		for (int i=1;i<=n;i++)
			if (que[i].front()==j){
				que[i].pop();
				while (vis[que[i].front()]) que[i].pop();
				tot[que[i].front()]++;
			}
		mx=0; j=0;
		for (int i=1;i<=m;i++)
			if (!vis[i]&&tot[i]>mx){ mx=tot[i]; j=i;}
		ans=min(ans,mx); vis[j]=true;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;

const int Inf = 100000000;
const long long mod = 1e9 + 7;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}	

long long n;
set <long long> Res;

int main()
{
	Fastio();
	cin >> n;
	for(long long i = 1; i <= 1000000; i++)
	{
		if((n - 1) % i == 0)
		{
			if(i != 1)
				Res.insert(i);
			if((n - 1) / i != 1)
				Res.insert((n - 1) / i);
		}
		if(n % i == 0)
		{
			long long temp = n;
			if(i != 1)
			{
				while(temp % i == 0)
				{
					temp /= i;
				}
				if(temp % i == 1)
				{
					Res.insert(i);
				}
			}
			temp = n;
			if((n / i) != 1)
			{
				while(temp % (n / i) == 0)
				{
					temp /= (n / i);
				}
				if(temp % (n / i) == 1)
				{
					Res.insert(n / i);
				}
			}
			
		}
	}
	cout << Res.size();
}

Measured memory_bytes: 3616
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	double p = 0.0;

	for (int i = 1; i <= N; i++) {
		int cnt = 0;
		int tmp = i;
		while (tmp < K) {
			tmp *= 2;
			cnt++;
		}
		p += 1.0 / N * (1.0 / pow(2, cnt));
	}
	printf("%0.12lf\n", p);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

int main(){
  int S,W;
  cin >> S >> W;

  cout << (S <= W ? "unsafe" : "safe") << endl;

  return 0;
}

Measured memory_bytes: 3640