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

using namespace std;

bool solve(char c1, char c2, int now, int des, string &s, string &t) {
	// cout << c1 << ": ";
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == c1) {
			now++;
		}
		if (now > des) {
			return true;
		}
		if (now > 1 && t[i] == c2) {
			now--;
		}
		// cout << now << " ";
	}
	// cout << endl;
	return false;
}

int main() {
	int n, m, l;
	cin >> n >> m >> l;
	int x, y;
	cin >> x >> y;
	string s, t;
	cin >> s >> t;
	if (solve('U', 'D', n - x + 1, n, s, t) || solve('D', 'U', x, n, s, t)) {
		cout << "NO" << endl;
	} else
	if (solve('L', 'R', m - y + 1, m, s, t) || solve('R', 'L', y, m, s, t)) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;	
	}
}

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

int main(){
  ll n;
  cin >> n;
  ll a[n+1];
  rep(i,n+1) cin >> a[i];
  if(n == 0) {
    if(a[0] == 1) cout << 1 << endl;
    else cout << -1 << endl;
    return 0;
  }
  vector<ll> d(n+1,INF);
  d[0] = 1 - a[0];
  if(d[0] < 0) {
    cout << -1 << endl;
    return 0;
  }
  for(int i = 1; i <= n; i++) {
    if(d[i-1] < INF) d[i] = d[i-1]*2 - a[i];
    if(d[i] < 0) {
      cout << -1 << endl;
      return 0;
    }
    if(i == n) d[i] += a[i];
  }
  if(a[n] > d[n]) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = a[n];
  ll num = a[n];
  for(int i = n-1; i >= 0; i--) {
    if(2*d[i] < num) {
      cout << -1 << endl;
      return 0;
    } else {
      num = min(d[i],num);
      num += a[i];
      ans += num;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4828
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int x;
  cin >> x;
  cout << (x == 1 ? 0 : 1) << endl;
}


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

int main(){
	int n;
	int card[52]={0};
	
	cin >> n;
	for(int i=0; i<n; ++i){
		char c;
		int a;
		cin >> c >> a;
	
		if(c=='S') card[a-1]=1;
		else if(c=='H') card[a-1+13]=1;
		else if(c=='C') card[a-1+26]=1;
		else if(c=='D') card[a-1+39]=1;
	}
	
	for(int i=0; i<52; ++i){
		if(card[i]==0){
			if(i<13) cout << "S ";
			else if(i<26) cout << "H ";
			else if(i<39) cout << "C ";
			else if(i<52) cout << "D ";
			
			cout << i%13+1 << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3084
n = int(input())
v_list = []
dict = {}

for i in range(n):
    s = input()
    if s in dict.keys():
        dict[s] += 1
    else:
        dict[s] = 1

max_id = max(dict.values())
ans_list = []

for i in dict:
    if dict[i] == max_id:
        ans_list.append(i)

ans_list = sorted(ans_list)

for i in ans_list:
    print(i)


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

typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, (n + 1) / 2) cout << a[n - 1 - i * 2] << " ";
    rep(i, n / 2) cout << a[n % 2 + i * 2] << " ";
    cout << "\n";
}

Measured memory_bytes: 2944
#include<iostream>
#include <algorithm>
using namespace std;
int tab[510][510] = {};
int table[510][510] = {};
int answer[100010] = {};
int main() {
	int n, m, Q;
	cin >> n;
	cin >> m;
	cin >> Q;
	int l, r;
	for (int i = 0;i < m;i++) {
		cin >> l;
		cin >> r;
		tab[r][l] += 1;
	}
	for (int i = 1;i <= n;i++) {
		for (int j = i;j >= 1;j--) {
			table[i][j] = table[i][j + 1] + tab[i][j];
		}
	}
	int p, q;
	for (int i0 = 0;i0 < Q;i0++) {
		cin >> p;
		cin >> q;
		for (int i = 1;i <= q;i++) {
			answer[i0] += table[i][p];
		}
	}
	for (int i = 0;i < Q;i++) {
		cout << answer[i] << endl;
	}
	return 0;
}


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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main() {
	ll N;
	string S;
	cin >> N >> S;
	for (auto i: S) {
		if (i + N <= 90) {
			cout << char(i + N);
		}else{
			cout << char(i + N - 26); 
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(N), b(N), c(M), d(M), result(N, 1);
  for(int i = 0; i < N; i++){
    cin >> a.at(i) >> b.at(i);
  }
  for(int i = 0; i < M; i++){
    cin >> c.at(i) >> d.at(i);
  }
  for(int i = 0; i < N; i++){
    int n = abs(a.at(i) - c.at(0)) + abs(b.at(i) - d.at(0));
    for(int j = 0; j < M; j++){
      if(n > abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j))){
        n = abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j));
        result.at(i) = j+1;
      }
    }
    cout << result.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    VL v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    ll ans = 0;
    rep(i, n - 1)
    {
        if (v[i] > v[i + 1])
        {
            ans += v[i] - v[i + 1];
            v[i + 1] = v[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4836
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

void solve()
{
	string s, t;
	cin >> s >> t;

	string temp = s;

	while(len(s) <= len(t))
	{
		s += temp;
	}

	int n = len(s);
	s += s;

	string f = t + '#' + s;
	int k = len(t);
	int m = len(f);
	vector<int> z(m, 0);

	int l = NIL, r = NIL;

	for(int i = 1; i < m; ++i)
	{
		if(i <= r)
			z[i] = min(z[i - l], r - i + 1);

		while(i + z[i] < m && f[i + z[i]] == f[z[i]])
			++z[i];

		if(i + z[i] - 1 >= r)
			l = i, r = i + z[i] - 1;
	}

	vector<int> jump(n, NIL);

	for(int i = 0; i < n; ++i)
	{
		int go = z[i + k + 1];

		if(go == k)
		{
			jump[i] = (i + go) % n;

#ifdef __LOCAL
			cout << i << " -> " << jump[i] << endl;
#endif
		}
	}

	vector<int> met(n, NIL);
	vector<int> ord;
	int answ = 0;

	for(int i = 0; i < n; ++i)
	{
		if(met[i] == NIL)
		{
			vector<int> st;

			for(int j = i; j != NIL; j = jump[j])
			{
				st.push_back(j);

				if(met[j] == i)
				{
					cout << NIL << endl;
					exit(0);
				}

				if(met[j] != NIL)
					break;

				met[j] = i;
			}

			while(!st.empty())
			{
				ord.push_back(st.back());
				st.pop_back();
			}
		}		
	}

	reverse(ord.begin(), ord.end());
	fill(met.begin(), met.end(), NIL);

	for(auto& i: ord)
	{
		if(met[i] == NIL)
		{
			int local = 0;

			for(int j = i; j != NIL; j = jump[j])
			{
				if(met[j] != NIL)
					break;

				++local;
				met[j] = i;
			}

			answ = max(answ, local - 1);
		}
	}

	cout << answ << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 31816
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <string.h>

using namespace std;

int main()
{
    int c=0;
    cin>>c;
    int o=0;
    for(int r=0;r<10;r++){
        for(int e=0;e<10;e++){
            if(r*e==c){
                o++;

            }
        }
    }
    if(o==0){
        cout<<"No";
    }

        else if(o!=0){
            cout<<"Yes";
        }

        return 0;
}


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

int main()
{
    int n,m,x,s=0,t=0;
    cin>>n>>m>>x;
    for(int i=0;i<m;i++){
      int p;
    cin>>p;
    if(p<x)s++;
    if(p>x) t++;
    }
    cout<<min(s,t)<<endl;

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N;
vector<int> A;
vector<vector<int>> dp;

int dfs(int i, int j){
  if(i+j == N) return 0;
  if(dp[i][j] != -1) return dp[i][j];

  int ret;
  if((i+j)%2 == 0){
    ret = -INF;
    chmax(ret, dfs(i+1, j)+A[i]);
    chmax(ret, dfs(i, j+1)+A[N-j-1]);
  }
  else{
    ret = INF;
    chmin(ret, dfs(i+1, j)-A[i]);
    chmin(ret, dfs(i, j+1)-A[N-j-1]);
  }

  return dp[i][j] = ret;
}

signed main() {
  cin >> N;

  A.resize(N);
  REP(i, N) cin >> A[i];

  dp = vector<vector<int>>(N+1, vector<int>(N+1, -1));

  cout << dfs(0, 0) << "\n";

  return 0;
}

Measured memory_bytes: 70912
let () =
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> a, b) in
        let rec loop i mmin mmax =
            if i = 0 then max 0 (mmax - mmin + 1) else
                let l, r = Scanf.sscanf (read_line ()) "%d %d" (fun l r -> l, r) in
                loop (i - 1) (max mmin l) (min mmax r)
        in
        Printf.printf "%d\n" (loop m 1 n)
    in
    main ()

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    Abra_Ka_Dabra

    int n;
    cin>>n;
    vector<ll> x;
    while(n--){
        ll tmp;
        cin>>tmp;
        x.push_back(tmp);
    }
    ll stock=0, money=1000;
    for(int i=0; i<x.size(); i++){
        if(i==x.size()-1 || x[i]>x[i+1]){
            money += (stock*x[i]);
            stock = 0;
        }
        else if(x[i]<x[i+1]){
            stock += (money/x[i]);
            money %= x[i];
        }
    }
    cout<<money<<"\n";

    return 0;
}


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

#define fori( tt,aa)      for(long long i= tt; i<aa; i++)
#define forj( yy,bb)      for(long long j=yy; j<bb; j++)
#define fork( uu,cc)      for(long long k=uu; k<cc; k++)
#define sz(v)    v.size()
#define all(v)   v.begin(), v.end()
#define endl "\n";
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define EPS 1e-7
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE; fast();

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string String;
typedef string str;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef pair<int, int> pii;

void fast(){
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(0);
}

ld pow (ll a, ll b);
ll numOfDigits(ll n);
ll BN (ll arr[], ll j, ll val);
ll n, d, p1, p2, p3, cnt;
int main()
{

    THINK_TWICE_CODE_ONCE;
    //freopen("test cases\\Points on Line.txt", "r", stdin);
    int n, k, c = 0;
    cin>>n>>k;

    fori(0, n){
        int a; cin>>a;
        if(a>=k) c++;
    }
    cout<<c;

    return 0;
}
ld pow (ll a, ll b){
    ld pow = 1;
    fori(0,b)
        pow *=a;
    return pow;
}
/*
ll BN (ll arr[], ll j, ll val){
int low = j;
int up = n-1;
ll ans = -1;
while(low<=up){
    ll mid = ((ll)low+ up)/2;
    if(abs(arr[mid]-val)<=d){
        ans = mid;
        low = mid+1;
    }else up = mid-1;
}
return ans;
}*/

ll numOfDigits(ll n){
    if(!n) return 1;
    return (ll)(log10(n)+1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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 RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,K;
    cin>>N>>K;
    ll numK=0;
    ll numhalfK=0;
    ll ans=0;
    if(K%2==0){
        REP1(i,N){
            if(i%K==0)numK++;
            if(i%K==(K/2))numhalfK++;
        }
        ans=numhalfK*numhalfK*numhalfK;
        ans+=numK*numK*numK;
    }else{
        REP1(i,N){
            if(i%K==0)numK++;
        }
        ans=numK*numK*numK;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<long long,long long>
#define ppii pair<long long,pair<long long,long long>>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
typedef vector<vector<long long>> vii;
typedef unsigned long long lint;
typedef unsigned long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e14;
const int MAX_N = 1 << 17;
const int cf = 100010;
///////////////////////////////////////////////////////////////////////////////
int n, C;
int tv[33][100010];
int main(void) {
	cin >> n >> C;
	for (int i = 0; i < n; i++)
	{
		int s, t, c; cin >> s >> t >> c;
		for (int j = s-1; j < t; j++) tv[c][j] = 1;

	}
	int ans = 0;
	for (int i = 0; i < 100010; i++)
	{	
		int cnt = 0;
		for (int j = 0; j < 33; j++) {
			if (tv[j][i] > 0) cnt++;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

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

const int maxn = 100010;
char s[maxn]; int N;

inline int gi()
{
	char ch; int ret = 0,f = 1;
	do ch = getchar(); while (!(ch >= '0'&&ch <= '9')&&ch != '-');
	if (ch == '-') f = -1,ch = getchar();
	do ret = ret*10+ch-'0',ch = getchar(); while (ch >= '0'&&ch <= '9');
	return ret*f;
}

int main()
{
	// freopen("A.in","r",stdin);
	// freopen("A.out","w",stdout);
	scanf("%s",s+1); N = strlen(s+1);
	int ans = 0;
	for (int i = 1,j;i <= N;i = j)
	{
		for (j = i;j <= N&&s[j] == s[i];++j); ++ans;
	}
	cout << ans - 1 << endl;
	return 0;
}


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<long> prime, sieve(31622, 1);
    for(long i = 2; i < 31622; ++i)
        if(sieve[i]){
            prime.push_back(i);
            for(auto j = i * i; j < 31622; j += i)sieve[j] = 0;
        }

    vector<long> a(N);
    long C;
    for(auto& i : a)cin >> i;
    cin >> C;
    long u{C};
    for(const auto i : a)u = __gcd(u, abs(i));

    vector<long> ans;
    for(const auto p : prime)
        if(u % p == 0 && (ans.push_back(p), 1))
            while(u % p == 0)u /= p;
        else if(p <= N && C % p == 0){
            vector<long> v(p);
            for(unsigned long j = 0, k = 0; j < N; ++j, k = k == p - 2 ? 0 : ++k)v[k] += a[j];
            if(none_of(v.begin(), v.end(), [&p](auto x){return x % p;}))ans.push_back(p);
        }
    for(const auto i : ans)cout << i << endl;
    if(u ^ 1)cout << u << endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a - b) < c) cout << c - (a - b) << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String text = sc.nextLine();
			text = text.replace('.', ',');
			text = text.replace(',', ' ');
			String[] word = text.split(" ");
			int count=0;
			
			for(int i=0; i<word.length; i++){		
				int n = word[i].length();
			
				if(n>=3 && n<=6) {
					if(count>0) System.out.print(" ");
					System.out.print(word[i].substring(0,n));
					count++;
				}
			}
			
			if(count>0) System.out.println();
		}
	
	}
}

Measured memory_bytes: 17116
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void getval(_T& a) {
	std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void E();

int main()
{
	E();
	fflush(stdout);
	return 0;
}

static void E()
{
	int N, K;
	getval(N, K);

	bool zero = false;
	std::vector<LLONG> ai(N);
	for (int i = 0; i < N; i++) {
		getval(ai[i]);
		if (ai[i] == 0) {
			zero = true;
		}
	}

	std::sort(ai.begin(), ai.end(), [](const LLONG& a, const LLONG& b) {
		return tp_abs(a) > tp_abs(b);
	});  //std::greater<LLONG>());

	int negCnt = 0;
	for (int i = 0; i < K; i++) {
		if (ai[i] < 0) {
			negCnt++;
		}
	}

	LLONG ans1 = 1;
	if (negCnt % 2) {
		int restNegIdx = -1;
		for (int i = K; i < N; i++) {
			if (ai[i] < 0) {
				restNegIdx = i;
				break;
			}
		}
		int minNegIdx = -1;
		for (int i = K - 1; i >= 0; i--) {
			if (ai[i] < 0) {
				minNegIdx = i;
				break;
			}
		}
		int minPosIdx = -1;
		for (int i = K - 1; i >= 0; i--) {
			if (ai[i] >= 0) {
				minPosIdx = i;
				break;
			}
		}
		int restPosIdx = -1;
		for (int i = K; i < N; i++) {
			if (ai[i] >= 0) {
				restPosIdx = i;
				break;
			}
		}
		if (((restPosIdx == -1) && (minPosIdx == -1)) ||
			((restNegIdx == -1) && (restPosIdx == -1))) {
			//	全部負の数が確定
			std::sort(ai.begin(), ai.end(), std::greater<LLONG>());
			//	少しでも大きな数になるよう，絶対値の小さいほうから使う
			for (int i = 0; i < K; i++) {
				ans1 = (ans1 * ai[i]) % MOD_NUM;
				if (ans1 < 0) ans1 += MOD_NUM;
			}
		}
		else {
			if (restPosIdx != -1) {
				for (int i = 0; i < K; i++) {
					if (i == minNegIdx) {
						ans1 = ans1 * ai[restPosIdx] % MOD_NUM;
					}
					else {
						ans1 = ans1 * ai[i] % MOD_NUM;
					}
					if (ans1 < 0) ans1 += MOD_NUM;
				}
			}
			if ((restNegIdx != -1) && (minPosIdx != -1)) {

				if ((restPosIdx == -1) || (ai[restPosIdx] * ai[minPosIdx] < ai[minNegIdx] * ai[restNegIdx])) {
					ans1 = 1;
					for (int i = 0; i < K; i++) {
						if (i == minPosIdx) {
							ans1 = ans1 * ai[restNegIdx] % MOD_NUM;
						}
						else {
							ans1 = ans1 * ai[i] % MOD_NUM;
						}
						if (ans1 < 0) ans1 += MOD_NUM;
					}
				}
			}
		}
	}
	else {
		for (int i = 0; i < K; i++) {
			ans1 = ans1 * ai[i] % MOD_NUM;
			if (ans1 < 0) ans1 += MOD_NUM;
		}
	}
	printf("%lld\n", ans1);
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define int long long
#define mod 1e18+10
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main() {
	int n;
	cin>>n;
	int ans=pow(2,(int)log2(n));
	cout<<ans<<"\n";
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int a, b, c; cin >> a >> b >> c;
	if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
	{
		cout << 0 << endl;
		return 0;
	}
	if (a == b &&b == c)
	{
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	while (1)
	{
		ans++;
		int na = b / 2 + c / 2;
		int nb = a / 2 + c / 2;
		int nc = a / 2 + b / 2;
		a = na; b = nb; c = nc;
		if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) break;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    cout << N*(N-1)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i < n; i++)
int main() {
  int n;
  cin >> n;
  long long x = 1000;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n-1) {
    int s = a[i];
    int t = a[i+1];
    if(s < t) {
      long long k = x/a[i];
      x %= s;
      x += k*t;
    }
  }
  cout << x;
}
      

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

int q;
bool reverse;
string s;
char hd[200009],tl[200009];
int hdcnt,tlcnt;

int main()
{
	cin >> s;
	cin >> q;
	char c;
	for(int i = 0,t,f;i<q;i++)
	{
		cin >> t;
		if(t==1)
		{
			reverse ^= 1;
			continue;
		}
		cin >> f >> c;
		//cout << reverse << endl;//
		if((f==1)^reverse)hd[++hdcnt] = c;
		else tl[++tlcnt] = c;
	}
	//cout << reverse << "!" << endl;//
	if(reverse==false)
	{
		for(int i = hdcnt;i>=1;i--)cout << hd[i];
		cout << s;
		for(int i = 1;i<=tlcnt;i++)cout << tl[i];
	}
	else
	{
		for(int i = tlcnt;i>=1;i--)cout << tl[i];
		for(int i = s.size()-1;i>=0;i--)cout << s[i];
		for(int i = 1;i<=hdcnt;i++)cout << hd[i];
	}
	return 0;
}

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

int main(){

	int H, W;

	while(1){

		cin >> H >> W;
		if(H == 0 && W == 0) break;

		for (int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i + j) % 2 == 0){
					cout << "#";
				}else{
					cout << ".";
				}
			}   
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


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

using namespace std;

#define ll long long

const int N=1e6+5;

int m,n,k,ans,l,r,u,v,x,tc,y,q,sz,d,dp[N][2],a[N];


char s[N];

set<ll> cnt;

int solve(int idx,int need){
    if (idx>=n)
        return 0;
    int &r=dp[idx][need];
    if (~r)
        return r;
    bool ok=false;
    r=0;
    if (!need){
        if (s[idx]!=s[idx+1])
            r=1+solve(idx+1,0);
        else
            r=1+solve(idx+1,1);
    }
    if (idx+1<n)
        r=max(r,1+solve(idx+2,0));
    return r;
}

int main(){ 
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    memset(dp,-1,sizeof dp);
    scanf("%s",s);
    n=strlen(s);
    printf("%d",solve(0,0));
}




Measured memory_bytes: 18176
#include <stdio.h>

int makeCombination(int, int *, int, int);

int main(){
  int i, n, A[20], m, q;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&m);

    if(makeCombination(n,A,m,0) == 1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int makeCombination(int n, int *A, int m, int x){
  int res;
  if(m == 0){
    return 1;
  }
  if(x >= n){
    return 0;
  }
   res = makeCombination(n,A,m,x + 1) || makeCombination(n,A,m - A[x],x + 1);
  return res;
}


Measured memory_bytes: 2108
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	A := ReadInts(N)
	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	s := 0
	for i := range A[1:] {
		s += A[(i+1)/2]
	}
	fmt.Println(s)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 5996
def f(a):
    # 4の時0,1,2,3,4の5つ→3桁いる
    a+=1
    if a==0:
        return 0
    ans=0
    # 10^3<=2^10
    for i in range(44):
        # 0桁目→周期2
        # 1桁目 4
        # 2 8
        loop = 1<<(i+1)
        cnt = (a//loop)*(loop//2)
        # 00..... 01111....11
        cnt+=max(0,(a%loop)-(loop//2))
        #その桁の1の数が奇数なら足し算
        if cnt%2==1:
            ans+=(1<<i)
    return ans
a,b=map(int,input().split())
print(f(b)^f(a-1))

Measured memory_bytes: 3060
chomp (my ($n, $k) = split / /, readline ARGV);
chomp (my @d = split / /, readline ARGV);

my %d;
@d{@d} = ();
my @l = sort grep { ! exists $d{$_} } 0..9;

my $it = rep_permutate(\@l, length $n);
while (my $s = $it->()) {
  my $s = join '', @$s;
  print +($s + 0) . "\n" and exit if $n <= $s;
}
print +($l[0] || $l[1]) . $l[0] x (length $n) . "\n";

sub rep_permutate {
  my @items = @{ shift() };
  my $num = shift;
  return unless 0 < $num;
  my $n = 0;
  sub {
    $n = $_[0] if defined $_[0];
    return if $n >= @items ** $num; # end of iteration
    my @res = ();
    unshift @res, $items[ int($n / @items ** $_) % @items ] for 0 .. $num - 1;
    $n++;
    \@res;
  }
}

Measured memory_bytes: 512
import collections


def distances(n, x, y):
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            yield min(j - i, abs(x - i) + abs(y - j) + 1)


N, X, Y = map(int, input().split())

c = collections.Counter(distances(N, X, Y))

for i in range(1, N):
    print(c[i])


Measured memory_bytes: 3956
# -*- coding: utf-8 -*-
import math

n ,m = (int(i) for i in input().split())
if abs(n - m) > 1:
    print(0)
elif n == m:
    print(math.factorial(n) * math.factorial(m) * 2 % (pow(10, 9) + 7))
else:
    print(math.factorial(n) * math.factorial(m) % (pow(10, 9) + 7))

Measured memory_bytes: 5196
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <functional>
#include <algorithm>
#include <random>
#include <cmath>
#include <climits>
int lower_bound(const std::vector<int> &array, const int target) {
	int left = 0, right = array.size() - 1;
	while (left < right) {
		if (array[(left + right) / 2] < target) {
			left = (left + right) / 2 + 1;
		}
		else {
			right = (left + right) / 2;
		}
	}
	return right;
}
int search(const int init, const int next, const std::vector<int> &numbers, std::vector<std::vector<bool>> &is_searched) {
	auto pos = lower_bound(numbers, next);
	if (numbers[pos] != next) return 1;
	else {
		if (is_searched[init][pos - init]) return 1;
		else {
			is_searched[init][pos - init] = true;
			return search(pos, next - numbers[init] + next, numbers, is_searched) + 1;
		}
	}
}
int main() {
	int n; std::cin >> n;
	std::vector<int> numbers(n); for (auto &n : numbers) std::cin >> n;
	std::sort(numbers.begin(), numbers.end());
	std::vector<std::vector<bool>> is_searched(n); for (auto i = 0; i < n; ++i) is_searched[i] = std::vector<bool>(n - i, false);
	auto max = 0;
	for (auto i = 0; i < n; ++i) {
		for (auto j = i + 1; j < n; ++j) {
			auto len = search(i, numbers[j], numbers, is_searched);
			if (len > max) max = len;
		}
	}
	std::cout << max << std::endl;
}


Measured memory_bytes: 4720
n, m, x = list(map(int, input().split()))
a = list(map(int, input().split()))

now = x

res1 = 0
for i in range(n - x - 1):
    now += 1
    if a.count(now):
        res1 += 1

now = x
res2 = 0
for i in range(x):
    now -= 1
    if a.count(now):
        res2 += 1

if res1 < res2:
    print(res1)
else:
    print(res2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n, s) for (LL i = (s); i < (n); i++)
#define SIZE 200001
using namespace std;
typedef long long int LL;
typedef long double LD;

int N, K, L;
// CT : Route, _CT : Group Stations
set<int> CT[2][SIZE], _CT[2][SIZE];
// ct : Group No
int ct[2][SIZE];

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

	cin >> N >> K >> L;
	int p, q, r, s, res[SIZE];
	memset(res, 0, sizeof(res));
	memset(ct, 0, sizeof(ct));

	while (K--) {
		cin >> p >> q;
		CT[0][p].insert(q);
		CT[0][q].insert(p);
	}
	while (L--) {
		cin >> r >> s;
		CT[1][r].insert(s);
		CT[1][s].insert(r);
	}

	REP(i, N+1, 1) {
		queue<int> que;
		set<int> cpy;
		// Find Routes
		REP(j, 2, 0) {
			if (ct[j][i] > 0) continue;
			ct[j][i] = i;
			que.push(i);
			_CT[j][i].insert(i);
			if (j == 1) res[i]++;
			while (que.size()) {
				int a = que.front();
				que.pop();
				for (int c : CT[j][a]) {
					if (_CT[j][i].count(c) > 0) continue;
					if (j == 1 && _CT[0][ct[0][i]].count(c)) {
						cpy.insert(c);
						res[i]++;
					}
					ct[j][c] = i;
					_CT[j][i].insert(c);
					que.push(c);
				}
			}
		}
		// Calculate result
		if (res[i] == 0) {
			for (int c : _CT[0][ct[0][i]]) {
				if (_CT[1][ct[1][i]].count(c) > 0) {
					cpy.insert(c);
					res[i]++;
				}
			}
		}
		// Copy result to other index
		for (int c : cpy) {
			res[c] = res[i];
		}
	}
	REP(i, N, 1) cout << res[i] << " ";
	cout << res[N] << endl;

	return 0;
}


Measured memory_bytes: 77312
function times(num1,num2){
  var num1str=(num1+"").split("").reverse();
  var num2str=(num2+"").split("").reverse();
  var L1=num1str.length;
  var L2=num2str.length;
  var newNumStr=[]
  for(var i=0;i<L1;i++){
    for(var j=0;j<L2;j++){
      if(newNumStr[i+j]===undefined)newNumStr[i+j]=0;
      newNumStr[i+j] += parseInt(num1str[i])*parseInt(num2str[j]);
    }
  }
  for(var k=0;k<10+10*(L1+L2);k++){
    if(newNumStr[k]===undefined)newNumStr[k]=0;
  }
  for(var k=0;k<2*(L1+L2);k++){
    if(newNumStr[k]===undefined)newNumStr[k]=0;
  }
  var l=0;
  while(newNumStr[l]||newNumStr[l]===0){
    newNumStr[l+1] += (newNumStr[l]-(newNumStr[l]%10))/10;
    newNumStr[l] = (newNumStr[l]%10).toString(10);
    l++;
  }
  newNumStr=newNumStr.reverse();
  while(isNaN(newNumStr[0])||newNumStr[0]==="0"){
    newNumStr.splice(0,1);
  }
  newNumStr=newNumStr.join("");
  return(newNumStr);
}

function adds(num1,num2){
  var num1str=(num1+"").split("").reverse();
  var num2str=(num2+"").split("").reverse();
  var L1=num1str.length;
  var L2=num2str.length;
  var newNumStr=[];
  for(var i=0;i<Math.max(L1,L2);i++){
    if(num1str[i]===undefined)num1str[i]=0;
    if(num2str[i]===undefined)num2str[i]=0;
  }
  for(var i=0;i<Math.max(L1,L2);i++){
    newNumStr[i]=parseInt(num1str[i])+parseInt(num2str[i]);
  }
  var l=0;
  while(newNumStr[l]||newNumStr[l]===0){
    newNumStr[l+1] += (newNumStr[l]-(newNumStr[l]%10))/10;
    newNumStr[l] = (newNumStr[l]%10+"");
    l++;
  }
  newNumStr=newNumStr.reverse();
  while(isNaN(newNumStr[0])||newNumStr[0]==="0"){
    newNumStr.splice(0,1);
  }
  newNumStr=newNumStr.join("");
  return(newNumStr);
}

function subtracts(num1,num2){
  var num1str=(num1+"").split("").reverse();
  var num2str=(num2+"").split("").reverse();
  var L1=num1str.length;
  var L2=num2str.length;
  var newNumStr=[];
  for(var i=0;i<Math.max(L1,L2);i++){
    if(num1str[i]===undefined)num1str[i]=0;
    if(num2str[i]===undefined)num2str[i]=0;
  }
  for(var i=0;i<Math.max(L1,L2);i++){
    newNumStr[i]=parseInt(num1str[i])-parseInt(num2str[i]);
  }
  var l=0;
  while(newNumStr[l]||newNumStr[l]===0){
    if(newNumStr[l]<0){
      newNumStr[l+1]--;
      newNumStr[l]+=10;
    }
    l++;
  }
  newNumStr=newNumStr.reverse();
  while(isNaN(newNumStr[0])||newNumStr[0]==="0"){
    newNumStr.splice(0,1);
  }
  newNumStr=newNumStr.join("");
  return(newNumStr);
}

function Main(input) {
    input = input.replace("\n","");
	input = input.split(' ');
        var K=parseInt(input[0]);
        var A=parseInt(input[1]);
        var B=parseInt(input[2]);
        var D=B-A;
        var E=K-A;
        var biscuit=0;
/*        var biscuit=((E<2)||(D<3))?(K+1):(E%2===0)?(A+E*D/2+1):(A+(E+1)*D/2);
console.log(biscuit);
*/
  if((E<1)||(D<3)){
    biscuit=K+1;
  }else if(E%2===0){
    biscuit=adds(adds(times(E/2,D),A),1);
  }else{
    biscuit=adds(times((E+1)/2,D),A);
  }
  console.log(biscuit);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7756
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
#define N 200010
#define inf 1000000007
typedef struct
{
    int u,v,next;
}Node;
Node e[N*3];
int head[N],vis[N],d[N];
int tot,l,r;
void add(int x,int y,int z)
{
    e[tot].u=y;
    e[tot].v=z;
    e[tot].next=head[x];
    head[x]=tot++;
}
void Spfa()
{
    int i,j,k,t;
    queue<int> q;
    memset(vis,0,sizeof(vis));
    for(i=l;i<=r;i++)
        d[i]=-inf;
    d[l]=0;
    vis[l]=1;
    q.push(l);
    while(!q.empty())
    {
        t=q.front();
        q.pop();
        vis[t]=0;
        for(i=head[t];i!=-1;i=e[i].next)
        {
            j=e[i].u;
            k=e[i].v;
            if(d[j]<d[t]+k)
            {
                d[j]=d[t]+k;
                if(vis[j]==0)
                {
                    vis[j]=1;
                    q.push(j);
                }
            }
        }
    }
}
int main()
{
    int i,j,k,x,y,z,n,m;
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    tot=0;
    l=inf;
    r=-inf;
    for(i=0;i<m;i++)
    {
        scanf("%d%d",&x,&y);
        x=x*2+1;
        y=y*2-1;
        add(x,y+1,1);
        l=min(l,x);
        r=max(r,y+1);
    }
    for(i=l;i<r;i++)
    {
        add(i,i+1,0);
        add(i+1,i,-1);
    }
    Spfa();
    printf("%d\n",d[r]);
    return 0;
}


Measured memory_bytes: 8832
import Control.Applicative
import Data.Bool (bool)

main :: IO ()
main = solve <$> f <*> f >>= putStrLn
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> [Int] -> String
solve [_, m] as = bool "No" "Yes" . (>= m) . length $ filter f as
  where
    w = sum as
    f x = 4 * m * x >= w


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

int main() {
    
    int N;
    int d[101];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> d[i];

    int flag[110] = {0};
    for (int i = 0; i < N; i++) {flag[d[i]]++;}

    int counter = 0;
    for (int i = 1; i <= 100; ++i) { 
        if (flag[i]) {  
            counter++;
        }
    }
    cout << counter << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

const int NMAX = 2525;
const int MMAX = 5000;
const ll INF = 1e18;

int M, D;

int main() {
    cin >> M >> D;
    int ans = 0;
    FOR (m, 1, M+1) FOR (d, 1, D+1) {
        int d10 = d/10;
        int d1 = d%10;
        if (d1 >= 2 && d10 >= 2 && d1*d10==m) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    n,k =map(int, input().split())
    l = list(map(int, input().split()))
    l = sorted(l, reverse=1)
    res = 0
    for i in range(k):
        res += l[i]
    print(res)
if __name__ == '__main__':
    main()

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

using namespace std;

const int N = 105;
const int maxn = 1e5 + 5;

int n, m, w[N], v[N];
long long dp[N][maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> w[i] >> v[i];
    memset(dp, -0x3f, sizeof dp);
    for (int i = 0; i <= m; i++) dp[0][i] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j >= w[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
        }
    }
    cout << dp[n][m];
    return 0;
}

Measured memory_bytes: 82304
/*
[abc126] D - Even Relation
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;

int N;
vector<pli> g[MAX_N];
bool ans[MAX_N];

void dfs(int v, ll h, int par = -1) {
    ans[v] = h % 2 == 0;
    for (auto &e : g[v]) {
        ll w = e.first;
        int to = e.second;
        if (to == par) {
            continue;
        }
        dfs(to, h + w, v);
    }
}

void solve() {
    dfs(0, 0);

    for (int i = 0; i < N; i++) {
        cout << (ans[i] ? '1' : '0') << endl;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        u--;
        v--;
        g[u].push_back({w, v});
        g[v].push_back({w, u});
    }

    solve();

    return 0;
}


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

int main()
{
    int N, flag=0;

    cin >> N;

    for (int i = 1; i < 10;i++){
        if(N%i==0){
            if(N/i<10){
                //cout << "Yes" << endl;
                flag = 1;
            }
            else
            {
                //cout << "No" << endl;
                
            }
        }
    }
    if(flag==1){
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#112B
nt = [int(i) for i in input().split()]
ctList = [[int(_) for _ in input().split()] for i in range(nt[0])]

minimunCost = 1001
for ct in ctList :
    if ct[0] < minimunCost and ct[1] <= nt[1] :
        minimunCost = ct[0]
if(minimunCost != 1001) :
    print(minimunCost)
else :
    print("TLE")

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int k,a,b;
    cin>>k;
    cin>>a>>b;
    if(a%k==0||b%k==0){
    	cout<<"OK";
    }else if((((a/k)+1)*k)<b){
    	cout<<"OK";
    }else cout<<"NG";
    return 0;
}


Measured memory_bytes: 3620
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1e5+10
#define mod 1e9 + 7
#define pii pair<int,int>
using namespace std;
const int N = 1e5 + 1;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	string s;
	cin>>s;
	n = s.length();
	for(int i=0;i<n/2;i++){
		if(s[i] != s[n-i-1]){
			cnt[0]++;
		}
	}
	cout<<cnt[0];
    return 0;
}
//.........

Measured memory_bytes: 256
/*
 * 2656.cc: Taps
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const double DINF = 1.0e60;

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  double t, d, ta, tb, da, db;
  cin >> t >> d >> ta >> tb >> da >> db;

  double va, vb, mindt = DINF;
  for (int ai = 0; (va = da * ai) <= d; ai++) {
    for (int bi = 0; va + (vb = db * bi) <= d; bi++) {
      double v = va + vb;
      if (v == 0.0) continue;
      double tt = (ta * va + tb * vb) / v;
      double dt = abs(t - tt);
      if (mindt > dt) mindt = dt;
    }
  }
  printf("%.10lf\n", mindt);
  return 0;
}

Measured memory_bytes: 1240
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

a,b,ab,x,y=map(int,input().split())
now=a*x+b*y
for i in range(1,10**5+1):
    now=min(now,a*(max(0,x-i))+b*(max(y-i,0))+ab*(i*2))
print(now)

Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;


using Graph = vector<vector<int>>;//グラフ型
void dfs(const Graph& G, int v/*根*/, vector<bool>& seen) {
	seen[v] = true;  //vを訪問済にする
	for (auto next_v : G[v]) { //訪問済にしたvとつながっている場所を順番に探す
		if (seen[next_v]) continue; //もし探索済みならスルー
		dfs(G, next_v, seen); //再帰的に探索
	}
}

void bfs(const Graph& G, queue<int>& que/*発見したが訪問はしていない*/, vector<int>& dist/*開始地点からの距離*/) {
	
	while (!que.empty()) {
		int v = que.front();//queのうち先頭のものからスタート
		que.pop();//先頭を削除

		for (int nv : G[v]) {//vとつながっている点を列挙
			if (dist[nv] != -1) continue;//発見済(=距離が格納されている)であればスルー
			dist[nv] = dist[v] + 1;//vとつながっている点に距離の情報を追加
			que.push(nv);//vとつながっている点を発見済にする
		}
	}
}

int main(void) {
	int n, m;
	cin >> n >> m;
	ll ans = 0;
	ans += n * (n - 1) / 2;
	ans += m * (m - 1) / 2;
	cout << ans;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	char s[3];
	int cnt,i;
	cnt=0;
	for(i=0;i<3;i++){
		scanf("%c",&s[i]);
		if(s[i]=='1'){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
N = int(input())


amari = []
while(N>0):
    if N%26 == 0:
        amari.append("z")
        N = N//26-1
    else:
        amari.append(chr(N%26+96))
        N = N//26
amari.reverse()
for i in range(len(amari)):
    print(amari[i],end = "")


Measured memory_bytes: 9184