akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long int in;

in dp[3005][3005],cp[3005][3005];

int main() 
{
	in n,l=1000000007,i,j;
	cin>>n;
	
	string s;
	cin>>s;
	
	dp[0][0]=1;
	cp[0][0]=1;
	
	for(i=1;i<3005;++i)
	{
	    cp[0][i]=(cp[0][i]+cp[0][i-1])%l;
	}

	for(i=1;i<n;++i)
	{
	    for(j=0;j<=i;++j)
	    {
	        if(s[i-1]=='>')
	        {
	            in r;
	            
	            if(j==0)
	            r=0;
	            else
	            r=cp[i-1][j-1];
	            
	            dp[i][j]=((cp[i-1][i-1]-r)%l+l)%l;
	        }
	        else
	        {
	            if(j==0)
	            dp[i][j]=0;
	            else
	            dp[i][j]=(cp[i-1][j-1])%l;
	        }
	    }
	    
	    for(j=0;j<3005;++j)
	    cp[i][j]=(dp[i][j])%l;
	    
	    for(j=1;j<3005;++j)
	    cp[i][j]=(cp[i][j]+cp[i][j-1])%l;
	    
	}
	
	in ans=0;
	
	for(i=0;i<n;++i)
	ans=(ans+dp[n-1][i])%l;
	
// 	for(i=0;i<n;++i)
// 	{
// 	    for(j=0;j<n;++j)
// 	    cout<<dp[i][j]<<" ";
// 	    cout<<"\n";
// 	}
	
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 141184
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a;
    cin >> a;
    string s;
    cin >> s;
    
    if (a>=3200)cout<<s<<endl;
    else cout<<"red"<<endl;
    
    return 0;
}

Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long a = sc.NextLong();
        long b = sc.NextLong();

        long answer = 0;
        if ((b - a) % 2 == 0)
        {
            answer = (b - a) / 2;
        }
        else
        {
            if ((a - 1) >= n - b)
            {
                answer = n - b;
                answer++;
                a = a + answer;
                answer += (n - a) / 2;
            }
            else
            {
                answer = a - 1;
                answer++;
                b = b - answer;
                answer += (b - 1) / 2;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

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

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

char buf[105];

int main() {
  int r, c;
  scanf("%d%d\n", &r, &c);
  for(int i = 0; i < c+2; i++) {
    printf("#");
  }
  printf("\n");
  for(int i = 0; i < r; i++) {
    scanf("%s", buf);
    printf("#%s#\n", buf);
  }
  for(int i = 0; i < c+2; i++) {
    printf("#");
  }
  printf("\n");
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

LL f(LL n)
{
    if (n < 2)
    {
        return 0;
    }
    return n * (n - 1) / 2;
}

int main()
{
    IOS;
    int n;
    cin >> n;
    LL ans = 0;
    vector<LL> a(n, 0), cnt(n + 1, 0);
    FOR(i, 0, n)
    {
        cin >> a[i];
        ++cnt[a[i]];
    }
    FOR(i, 0, n + 1)
    {
        if (cnt[i] >= 2)
        {
            ans += f(cnt[i]);
        }
    }
    FOR(i, 0, n)
    {
        if (cnt[a[i]] >= 2)
        {
            cout << ans - f(cnt[a[i]]) + f(cnt[a[i]] - 1) << '\n';
        }
        else
        {
            cout << ans << '\n';
        }
    }
}


Measured memory_bytes: 5760
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;

int main() {
  int N,M;
  cin>>N>>M;
  int m=(2*M)+1;
  int ans=N/m;
  int ans1=N%m;
  if(ans1>0)
    ans+=1;
  cout<<ans;  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int a, b;
    cin >> a >> b;
    cout << max(a+b,max(a-b, a*b)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    vector<string> S(N);
    for(auto& in:S) cin >> in;
    map<char,ll> mp;
    string march = "MARCH";
    for(auto s:S){
        if(find(march.begin(),march.end(),s.front())==march.end()) continue;
        mp[s.front()]++;
    }
    for(int i = 0; i < (1<<5);i++){
        if(__builtin_popcount(i)!=3) continue;
        ll T = 1;
        for(int j = 0; j < 5;j++){
            if((i>>j)&1){
                T *= mp[march[j]];
            }
        }
        res += T;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <bitset>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REP1(i, n) for(int i = 1; i <= (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define ZERO(a) memset(a, 0, sizeof(a))

#define RAD(d) (PI * (d) / 180)
#define DEG(r) (180.0 * (r) / PI)

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

template<class T> void dump(const vector<T> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

template<class T> void dump(int w, int h, const vector<T> &v)
{
	REP(j, h){
		REP(i, w-1){ cout << v[j * w + i] << " "; }
		cout << v[j * w + w-1] << endl;
	}
}

template<class T> T accumulate(const vector<T> &v)
{
	T sum = 0;
	REP(i, SZ(v)){ sum += v[i]; }
	return sum;
}

template<class T> struct Matrix
{
	T w, h;
	vector<T> A;
	Matrix(T w_, T h_) : w(w_), h(h_), A(w * h) {}
	T get(T x, T y) const { return A[y * w + x]; }
};

template<class T> void input(Matrix<T> &m)
{
	REP(j, m.h){
		REP(i, m.w){
			cin >> m.A[j * m.w + i];
		}
	}
}

template<class T> Matrix<T> prod(const Matrix<T> &a, const Matrix<T> &b)
{
	Matrix<T> m(b.w, a.h);

	REP(j, m.h){
		REP(i, m.w){
			ll c = 0;
			REP(k, a.w){
				c += a.A[j * a.w + k] * b.A[k * b.w + i];
			}
			m.A[j * m.w + i] = c;
		}
	}

	return m;
}

void dump(const Matrix<ll> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%lld ", m.A[j * m.w + i]); }
		printf("%lld\n", m.A[j * m.w + m.w-1]);
	}
}

void dump(const Matrix<double> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%f ", m.A[j * m.w + i]); }
		printf("%f\n", m.A[j * m.w + m.w-1]);
	}
}

string &to_upper(string &s)
{
	REP(i, s.length()){
		if('a' <= s[i] && s[i] <= 'z'){
			s[i] -= 32;
		}
	}

	return s;
}

string &to_lower(string &s)
{
	REP(i, s.length()){
		if('A' <= s[i] && s[i] <= 'Z'){
			s[i] += 32;
		}
	}

	return s;
}

template <class T> vector<T> get_divisors(T n)
{
	vector<T> ret;
	for(T i = 1; i * i <= n; i++){
		if(n % i == 0){
			ret.push_back(i);
			if(i * i != n)
				ret.push_back(n / i);
		}
	}
	sort(ALL(ret));
	return ret;
}

int main()
{
	int A, B, K;
	cin >> A >> B >> K;

	for(int i = min(A, B); i > 0; i--){
		if(A % i == 0 && B % i == 0){
			K--;
			if(K == 0){
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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 dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll n, x; 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> x;
    vll a(n);
    rep(i, 0, n) cin >> a[i];
    ll sum = a[0], ans = 0;
    rep(i, 1, n) {
        sum += a[i];
        if (sum > x) {
            ans += sum - x;
            a[i] -= sum - x;
        }
        sum = a[i];
    }
    if (sum > x) ans += sum - x;
    cout << ans << endl;
    return 0;
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj(100001);
int ret=0;
vector<bool> vu(100001);

void dfs(int node){
	for (auto& i:adj[node]){
		if (!vu[i]){
			vu[i]=true;
			dfs(i);
		}
	}
}

int main(){
	int n,m;
	cin >> n >> m;
	for (int i=0; i<m; ++i){
		int a,b,c;
		cin >> a >> b >> c;
		adj[a].emplace_back(b);
		adj[b].emplace_back(a);
	}
	for (int i=1; i<=n; ++i){
		if (!vu[i]){
			vu[i]=true;
			++ret;
			dfs(i);
		}
	}
	cout << ret;
}


Measured memory_bytes: 8832
def main():
    N, K = map(int, input().split())
    lst_D = list(input().split())

    cost = N
    while True:
        for c in str(cost):
            if c in lst_D:
                break
        else:   # break しなかったときのみ実行される
            print(cost)
            break
        cost += 1


if __name__ == "__main__":
    main()

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

int main() {
	
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<char>> s(h, vector<char>(w));
	rep(i, h){
		rep(j, w){
			cin >> s[i][j];
		}
	}
	vector<vector<int>> ans(h, vector<int>(w));
	int cnt = 1;
	rep(i, h){
		bool is_first = true;
		rep(j, w){
			if(s[i][j] == '#'){
				if(is_first){
					for(int l = j; ; l--){
						ans[i][l] = cnt;
						if(l <= 0) break;
					}
					is_first = false;
				}
				for(int r = j; ; r++){
					ans[i][r] = cnt;
					if(r >= w-1) break;
					else if(s[i][r+1] == '#') break;
				}
				cnt++;
			}
		}
	}
	
	bool is_first = true;
	rep(i, h){
		if(ans[i][0] != 0){
			if(is_first){
				for(int u = i; ; u--){
					ans[u] = ans[i];
					if(u <= 0) break;
				}
				is_first = false;
			}
			for(int d = i; ; d++){
				ans[d] = ans[i];
				if(d >= h-1) break;
				else if(ans[d+1][0] != 0) break;
			}
		}
	}
	
	rep(i, h){
		rep(j, w){
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

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


// Useful container manipulation / traversal macros
#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(a,b)       ( (b).find(a) != (b).end())
#define tr(c,i)       for(auto i = (c).begin(); i != (c).end(); i++)
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb             push_back
#define fill(a,v)      memset(a, v, sizeof a)

typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    string s;
    cin>>s;

    int co1 = 0, co2 = 0;
    fori(i, 0, s.size()-1){
        
        if(i%2){
            if(s[i] != '1')
                co1 += 1;
        } else {
            if(s[i] != '0')
                co1 += 1;
        }
    }

    fori(i, 0, s.size()-1){
        
        if(!(i%2)){
            if(s[i] != '1')
                co2 += 1;
        } else {
            if(s[i] != '0')
                co2 += 1;
        }
    }
    
    cout<<min(co1, co2);

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

int main(){
    int N, R, L;
    while(cin >> N >> R >> L && N){
        const int B = sqrt(N);
        vector<int> bucket((N - 1) / B + 1);
        vector<int> point(N + B, INT_MIN);
        REP(i, N) point[i] = 0;
        int last_time = 0;
        int camera_id = 0;
        vector<int> answer(N);
        for(int i = 0; i < R; i++){
            int d, t, x;
            scanf("%d %d %d", &d, &t, &x);
            d--;
            point[d] += x;
            if(point[d] > bucket[d / B]){
                bucket[d / B] = point[d];
            }else if(point[d] - x == bucket[d / B]){
                bucket[d / B] = *max_element(point.begin() + (d / B) * B, point.begin() + (d / B + 1) * B);
            }
            answer[camera_id] += t - last_time;
            last_time = t;
            if(camera_id == d && x < 0){
                int k = max_element(bucket.begin(), bucket.end()) - bucket.begin();
                camera_id = max_element(point.begin() + k * B, point.begin() + (k + 1) * B) - point.begin();
            }else if(point[d] > point[camera_id]){
                camera_id = d;
            }else if(point[d] == point[camera_id] && d < camera_id){
                camera_id = d;
            }
            assert(camera_id >= 0 && camera_id < N);
            //REP(i, N) cout << point[i] << " "; cout << endl;
            //REP(i, (N - 1) / B + 1) cout << bucket[i] << " "; cout << endl;
            //printf("time:%d point[%d] += %d camera: %d\n", t, d + 1, x, camera_id + 1);
        }
        answer[camera_id] += L - last_time;
        cout << max_element(answer.begin(), answer.end()) - answer.begin() + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for(int x = 0; x <= K; x++){
        for(int y = 0; y <= K; y++){
            int z = S - x - y;
            if(z >= 0 && z <= K){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
input = gets.to_s
parameter = input.split(" ")[0].to_i
numOfA    = input.split(" ")[1].to_i
numOfB    = input.split(" ")[2].to_i

if numOfA < numOfB then
    maxOfBoth = numOfA
elsif numOfB < numOfA then
    maxOfBoth = numOfB
elsif numOfA == numOfB then
    maxOfBoth = numOfA
end

if numOfA + numOfB > parameter then
    minOfBoth =  numOfA + numOfB - parameter
elsif numOfA + numOfB < parameter then
    minOfBoth = 0
elsif numOfA + numOfB == parameter then
    minOfBoth = 0
end

minOfBoth = minOfBoth.to_s

puts "#{maxOfBoth} #{minOfBoth}"


Measured memory_bytes: 1788
A,B,C,D = map(int,input().split())
counta = 0
countb = 0
while True:
    C = C - B
    countb += 1
    if C <= 0:
        break
while True:
    A = A - D
    counta += 1
    if A <= 0:
        break
if counta >= countb:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9180
/*
	Nishant Singh
	nishant.ns19@gmail.com
*/
#include <bits/stdc++.h>
#include <functional> 
#include <iostream> 
// ******** Big Integer ********
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #define ll1024  int1024_t
// ******** Big Integer ********
// ******** Using PBDS ********
// #include <ext/pb_ds/assoc_container.hpp> // Common file 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ook order_of_key    //count of strictly smaller elements
// #define fbo find_by_order   //find element at an index 
// ******** Using PBDS ********
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vll vector<ll>
#define vec vector
#define setcount(x) __builtin_popcountll(x)
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define REV(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define in insert
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
#define pq priority_queue
#define ffl fflush(stdout)
#define mset multiset
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define ub upper_bound
#define lb lower_bound 
#define ln "\n"
#define Y "YES"
#define N "NO"
ll const mod=1e9 + 7;
ll const inf=2e18;
// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//                 os; 
// ******** Using PBDS ********
inline ll add(ll a,ll b) 
{ 
	return (a%mod + b%mod + mod)%mod; 
}
inline ll mul(ll a,ll b) 
{ 
	return (a%mod * b%mod + mod)%mod; 
}
inline ll sub(ll a,ll b) 
{ 
	return (a%mod - b%mod + mod)%mod; 
}
ll gcd(ll a,ll b)
{
	if (b == 0) 
		return a; 
	return gcd(b, a % b);  
}
ll modexp(ll x, ll n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}
ll modinv(ll n)
{
	return modexp(n,mod-2);
}
// ******** GLOBAL VARIABLES ********
// ******** GLOBAL VARIABLES ********
void solve(){
	ll n;
	cin>>n;
	if(n<600)
	{
		cout<<8;
		return;
	}
	if(n<800)
	{
		cout<<7;
		return;
	}
	if(n<1000)
	{
		cout<<6;
		return;
	}
	if(n<1200)
	{
		cout<<5;
		return;
	}
	if(n<1400)
	{
		cout<<4;
		return;
	}
	if(n<1600)
	{
		cout<<3;
		return;
	}
	if(n<1800)
	{
		cout<<2;
		return;
	}
	if(n<2000)
	{
		cout<<1;
		return;
	}
}  
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll T=1;
	// cin>>T; 	
	for(int t=1;t<=T;t++)
	{
		// cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt(),e=sc.nextInt(),k=sc.nextInt();
		System.out.println(e-a>k?":(":"Yay!");
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
 
#define A_MAX 1000000
 
using namespace std;
 
int scanint() { 
    char c = getchar_unlocked();
    int x = 0;
    while (c > 47) {
        x = (x << 3) + (x << 1) + c - 48;
        c = getchar_unlocked();
    }
    return x;
} 
 
int min_factor[A_MAX + 1];
int q[A_MAX + 1];
int a[A_MAX + 1];
int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };
 
int main() {
 
    for (int i = 2; i <= A_MAX; ++i) {
        if (!min_factor[i]) {
            min_factor[i] = i;
        }
        int j = 0;
        for (int p = primes[0]; ; p = primes[++j]) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor[i]) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }
 
    int N = scanint();
    for (int i = 0; i < N; ++i) {
        ++a[scanint()];
    }
 
    bool is_pairwise_coprime = true;
    for (int n = A_MAX; n > 1; --n) {
        int an = a[n];
        if (an) {
            if (an > 1) {
                if (an == N) {
                    printf("not coprime\n");
                    return 0;
                }
                is_pairwise_coprime = false;
            }
            a[min_factor[n]] += an;
            a[q[n]] += an;
        }
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }
 
    return 0;
}

Measured memory_bytes: 15364
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    //int t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,cnt=0,sum=0;
        ll arr[300000];
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        k=arr[0];
        for(i=1;i<n;i++)
        {
            k^=arr[i];
        }
        for(i=0;i<n;i++)
        {
            l=arr[i]^k;
            cout<<l<<" ";
        }



    }
}


Measured memory_bytes: 5092
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** *******  *** ************* **
*** ******** ** *************** *
**********_**********************
* |   /  / \  \     /    /\     *
* |  /  |   |  \   /    /  \    *
* | /   |   |   \ /    /    \   *
* |+\   |   |    |    /______\  *
* |  \  |   |    |   |        | *
* |   \  \_/     |   |        | *
********************************/
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a<b) ? b : a))
#define remin(a, b) (a = ((a<b) ? a : b))
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout<<fixed<<setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

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

const lli N = 1e5 + 1;
lli a[N], dp[N], n;

lli fun(lli pos){
    if(pos==n-1) return 0;
    if(dp[pos]!=-1) return dp[pos];
    lli res = 1e14;
    if(pos+1 < n) remin(res, abs(a[pos]-a[pos+1])+fun(pos+1));
    if(pos+2 < n) remin(res, abs(a[pos]-a[pos+2])+fun(pos+2));
    return dp[pos] = res;
}

void solve(){
    memset(dp, -1, sizeof dp);
    cin >> n;
    NA(i,0,n) cin >> a[i];
    cout << fun(0) ;
    return;
}
int main(){
    fastIO;
    lli t = 1;
    // cin>>t;
    NA(i,0,t){
        solve();
    }
    return 0;

}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    if (n == 0) {
      cout << 0 << endl;
      return 0;
    }
    vii ans;
    while (n != 0) {
      int r = n % 2;
      if (r < 0) {
        ans.pb(1);
        n--;
        n /= -2;
      } else {
        ans.pb(r);
        n /= -2;
      }
    }
    reverse(ALL(ans));
    fore(x, ans) cout << x;
    cout << "\n";
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int a=scanner.nextInt();
		int b=scanner.nextInt();
		if(a<b) {
			System.out.println("a < b");
		}else if(a>b) {
			System.out.println("a > b");
		}else if(a==b) {
			System.out.println("a == b");
		}

	}

}


Measured memory_bytes: 26220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
 
typedef pair<long long, long long> ii;
#define S second
#define F first
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;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll a[3005][3005];
ll dp[3005][3005][4];

int main() {
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
 
    ll n,m,k;
    cin>>n>>m>>k;
    
    for (int i = 0; i<=n; ++i)
    {
        for (int j = 0; j<=m; ++j)
        {
            a[i][j]=0;
        }
    }

    for (int i = 0; i < k; ++i)
    {
        ll a1,b1,c1;
        cin>>a1>>b1>>c1;
        a[a1][b1]=c1;
    }

    for (int i = 0; i<=n; ++i)
    {
        for (int j = 0; j<=m; ++j)
        {
            for (int k = 0; k<4; ++k)
            {
                dp[i][j][k]=0;   
            }
        }
    }

    for (int i = 1; i<=n; ++i)
    {
        for (int j = 1; j<=m; ++j)
        {
            if(a[i][j]){
                dp[i][j][0] = 0;
                dp[i][j][1] = max(dp[i][j-1][1], a[i][j] + max({dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3]}));
                dp[i][j][1] = max(dp[i][j][1], max(dp[i][j-1][1], a[i][j] + dp[i][j-1][0]));
                dp[i][j][2] = max(dp[i][j-1][2], a[i][j] + dp[i][j-1][1]);
                dp[i][j][3] = max(dp[i][j-1][3], a[i][j] + dp[i][j-1][2]);
            }
            else{
                dp[i][j][0] = max({dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3]});
                dp[i][j][1] = dp[i][j-1][1];
                dp[i][j][2] = dp[i][j-1][2];
                dp[i][j][3] = dp[i][j-1][3];
            }
        }
    }

    cout<<max({dp[n][m][0], dp[n][m][1], dp[n][m][2], dp[n][m][3]});

    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const long long MAXN = 1e9 + 9;
const long long SIZE = 2e5 + 5;
const long long MOD = 1e9 + 7;


int main() { speedhack()
	
	int N, have = 0;

	cin >> N;

	while (N > have)
		have += 1000;
	
	cout << have - N << endl;

	return 0;
}

Measured memory_bytes: 3648
import sys
import decimal
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

def main():
    decimal.getcontext().prec = 100
    a, b = input().split()
    a = int(a)
    b = decimal.Decimal(b)
    # print(a, b)
    print(int(b*a))
    return

if __name__ == "__main__":
    main()


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

using namespace std;

const int Size = 100000;
int main(int argc, char* argv[])
{
	int N;
	int M;
	cin >> N;
	cin >> M;
	int minID = 0;
	int maxID = Size+1;
	for (int i = 0; i < M; ++i)
	{
		int Li, Ri;
		cin >> Li;
		cin >> Ri;
		minID = std::max(minID, Li);
		maxID = std::min(maxID, Ri);
	}
	int result = maxID - minID;
	if (result < 0)
	{
		std::cout << 0 << std::endl;
	}
	else
	{
		std::cout << result + 1 << std::endl;
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
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; }
const long long INF = 1LL << 60;
const int inf = 1001001001;

int main(){

    ll n;
    cin >> n;
    vector<ll> p(n),q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<ll> a(n);
    rep(i,n) a[i]=i+1;

    map<vector<ll>,ll> mp;
    do{
        mp[a]=mp.size();
    }while(next_permutation(a.begin(),a.end()));

    ll ans=abs(mp[p]-mp[q]);
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}

signed main() {
	int n, a = 0, b = 0, ab = 0, ba = 0;
	cin >> n;
	rep(i, n) {
		string s;
		cin >> s;
		if (s[0] == 'B' && s[s.size() - 1] == 'A')ba++;
		else if (s[0] == 'B')b++;
		else if (s[s.size() - 1] == 'A')a++;
		rep(i, s.size() - 1) {
			if (s[i] == 'A' && s[i + 1] == 'B') {
				ab++;
			}
		}
	}
	if (a != 0 || b != 0) {
		cout << ab + ba + min(a, b) << endl;
	}
	else {
		cout << ab + max(ba - 1, (ll)0) << endl;
	}
}

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

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int A, B;
    cin >> A >> B;

    int ans = 0;
    ans += max(A, B);
    if (A < B) B--;
    else A--;
    ans += max(A, B);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
	int n;
	long long int k;
	cin >> n >> k;
	vector<int> a(n+1);
	for(int i=1;i<=n;++i) cin>>a[i];
	int lo=1, hi=1;
	do{
		lo = a[lo];
		hi = a[hi];
		hi = a[hi];
	} while(lo!=hi);
	lo = 1;
	int l1=1, l2=0;     //  |------|----------|
	                //     l1       l2(loop)
	while(l1!=k && lo!=hi) {
		lo=a[lo];
		hi=a[hi];
		++l1;
	}
	if(l1==k) {cout << a[lo] << endl; return 0;}
	k-=l1;
	do {
		hi=a[hi];
		++l2;
	} while(lo!=hi);
	k%=l2;
	l2=0;
	while(l2!=k) {
		lo=a[lo];
		++l2;
	}
	cout << a[lo] << endl;
	return 0;
}


Measured memory_bytes: 4052
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.L;
		long a=n;
		int e=0;
		while(a!=1){
			a>>=1;
			e++;
		}
		Console.WriteLine("{0}",(1L<<(e+1))-1);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
void yes(){
  cout << "Yes" << endl;
  exit(0);
}

void no(){
  cout << "No" << endl;
  exit(0);
}

int main() {
  string s; cin >> s;
  map<char, ll> mp;
  REP(i, s.size()){
    mp[s[i]]++;
  }
  if(mp['N']>0 && mp['S'] == 0) no();
  if(mp['S']>0 && mp['N'] == 0) no();
  if(mp['W']>0 && mp['E'] == 0) no();
  if(mp['E']>0 && mp['W'] == 0) no();
  yes();
}

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

int ok[6][4002];//0:(a,b),1:(b,a),2:(a,c),3:(c,a),4:(b,c),5:(c,b)

void CompStr(string a, string b, int i) {
  rep(j, a.size()) for (int k=j; k < min(a.size(), b.size()+j); k++) {
    if ((a.at(k) != '?') && (b.at(k-j) != '?') && (a.at(k) != b.at(k-j))) {
      ok[i][j] = 0; break;
    }
  }
}

int minLen(int ab, int bc, int ac, int as, int bs, int cs) {
  int min = as + bs + cs;
  rep(i, as+1) rep(j, max(bs+1, as-i+1)) {
    if ((ok[ab][i] == 1) && (ok[bc][j] == 1) && (ok[ac][i+j] == 1)) {
      int len = max(max(as, i+bs), i+j+cs);// calculate the length of the corresponding string
      if (min > len) min = len;
    }
  }
  return min;
}

int main() {
  string a, b, c;
  int as, bs, cs;
  cin >> a >> b >> c;
  as = a.size(); bs = b.size(); cs = c.size();
  rep(i, 6) rep(j, 4002) ok[i][j] = 1;
  CompStr(a, b, 0); CompStr(b, a, 1);
  CompStr(a, c, 2); CompStr(c, a, 3);
  CompStr(b, c, 4); CompStr(c, b, 5);
  int min = as + bs + cs; int minl;
  //0:(a,b),1:(b,a),2:(a,c),3:(c,a),4:(b,c),5:(c,b)
  minl = minLen(0, 4, 2, as, bs, cs); if (min > minl) min = minl; //abc
  minl = minLen(2, 5, 0, as, cs, bs); if (min > minl) min = minl; //acb
  minl = minLen(1, 2, 4, bs, as, cs); if (min > minl) min = minl; //bac
  minl = minLen(4, 3, 1, bs, cs, as); if (min > minl) min = minl; //bca
  minl = minLen(3, 0, 5, cs, as, bs); if (min > minl) min = minl; //cab
  minl = minLen(5, 1, 3, cs, bs, as); if (min > minl) min = minl; //cba
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
typedef long long int lli;
int main(){
	int N,A,B;
	lli sum=0;
	P W[200000];
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A>>B;
		W[i]=P(B,A);
	}
	sort(W,W+N);
	for(int i=0;i<N;i++){
		sum+=W[i].second;
		if(sum>W[i].first){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

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

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;
}

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i,N)cin >> h[i];
    vector<int> dp(N);
    rep(i,N)dp[i]=INF;
    dp[0]=0;
    repX(i,N,1){
        repX(j,K+1,1){
            if(i-j>=0)chmin(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
        }
    }
    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
 
void solve(){
 
 
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();

    int n,x,y;cin>>n>>x>>y;
    x--,y--;
    vi ans(n,0);
    rep(i,n)rep(j,n)if(i<j){
        int d=n+1;
        d=min(d,j-i);
        d=min(d,abs(i-x)+1+abs(j-y));
        d=min(d,abs(i-y)+1+abs(j-x));
        ans[d]++;
    }
    repA(i,1,n-1)cout<<ans[i]<<'\n';

	return 0;
}
 



Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int N=100005;
int n,a[N],b[N],i,h[N],xb=1,c[N<<1],f[N],soa[N],sob[N];
struct edge{int to,next;}e[N<<2];
bool vi[N<<1];
inline void addedge(int x,int y){
	e[++xb]=(edge){y,h[x]};h[x]=xb;
	e[++xb]=(edge){x,h[y]};h[y]=xb;
}
void dfs(int x){
	for(int&i=h[x];i;i=e[i].next)if(!vi[i>>1]){
		vi[i>>1]=1;dfs(e[i].to);c[++xb]=x;
	}
}
void dfs2(int x,int fa){
	for(int i=h[x];i;i=e[i].next)if(e[i].to!=fa)f[x]-=f[e[i].to];
	for(int i=h[x];i;i=e[i].next)if(e[i].to!=fa)dfs2(e[i].to,x);
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(i=1;i<=n;++i){
		cin>>a[i],a[i]==-1?a[i]=0:0;
		addedge(i,a[i]);++soa[a[i]];
	}
	for(i=1;i<=n;++i){
		cin>>b[i],b[i]==-1?b[i]=0:0;
		addedge(i,b[i]);++sob[b[i]];
	}
	for(i=1;i<=n;++i)if((soa[i]-sob[i])&1)return cout<<"IMPOSSIBLE"<<'\n',0;
	xb=0;dfs(0);
	cout<<"POSSIBLE"<<'\n';
	for(i=0;i<xb;++i){
		if(a[c[i+1]]==c[i])f[c[i+1]]=1;
		if(a[c[i]]==c[i+1])f[c[i]]=-1;
	}
	xb=0;for(i=1;i<=n;++i)addedge(a[i],i);
	dfs2(0,0);for(i=1;i<=n;++i)cout<<f[i]<<' ';
	return 0;
}

Measured memory_bytes: 13184
#!/usr/bin/env python3
# binary search 1

from bisect import bisect_left, bisect_right

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cumsum_b = [0 for _ in range(m+1)]
for i in range(1,m+1):
    cumsum_b[i] = cumsum_b[i-1] + b[i-1]
cumsum_a = [0 for _ in range(n+1)]
for i in range(1,n+1):
    cumsum_a[i] = cumsum_a[i-1] + a[i-1]

# print('cumsum_b =', cumsum_b)
ans = -1
for i in range(n+1):
    res = k-cumsum_a[i]
#    print('cumsum_a[{}] ='.format(i), cumsum_a[i])
#    print('res =', res)
    if res < 0:
        break
    bl = bisect_right(cumsum_b, res) - 1 
#    print('i =', i)
#    print('bl =', bl)
    tmp = i + bisect_right(cumsum_b, res) - 1 
    if ans <= tmp:
        ans = tmp 

print(ans)

Measured memory_bytes: 49008
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int a, b, c, x;
  cin >> a >> b >> c >> x;

  int ans = 0;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if (i * 500 + j * 100 + k * 50 == x) ans++;
      }
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256