akhauriyash/Code-Regression huggingface dataset:
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s, t; cin >> s >> t;
	set<char> c1; fore(e, s) c1.insert(e);
	fore(e, t) if(!c1.count(e)) { println("-1"); return 0; }
	map<char, set<int>> occ;
	forl(i, 0, s.length()) occ[s[i]].insert(i);
	ll pos = -1, its = 0;
	fore(e, t) {
		auto it = occ[e].upper_bound(pos);
		if(it == occ[e].end()) {
			pos = *occ[e].begin();
			its++;
		}
		else {
			pos = *it;
		}
	}
	println((int)s.length()*its+pos+1);
}


Measured memory_bytes: 5200
#include <stdio.h>

int solve(int, int);

int n, q, A[20];
int s[21][2001];

int main(void)
{
	int i, j, k, m;
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	
	for(j=0; j<n; j++) {
		for(k=0; k<2001; k++) {
			s[j][k] = -1;
		}
	}
	
	for (i=0; i<q; i++) {
		scanf("%d",&m);
		if( solve(0,m) ) {
			printf("yes\n");
		} else {
			printf("no\n");
		}
	}
	
	return 0;
}

int solve(int i, int m)
{
	if(m==0) return 1;
	if( i==n || m<0 ) return 0;
	if(s[i][m] != -1) return s[i][m];
	s[i][m] = solve(i+1, m) || solve(i+1,m-A[i]);
	return s[i][m];
}

Measured memory_bytes: 740
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	if (a=="hi"||a=="hihi"||a=="hihihi"||a=="hihihihi"||a=="hihihihihi")
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


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

#define N 300

static int n;
static int m;
static int c[ N ];
static int v[ N ];
static int d[ N ];
static int l[ N ];
const static int *p;

static int k_operafan[ N + 1 ][ N ];

int
dpFSA (
  const int m,
  const int k
  )
{
  int i;

  if ( k >= n ) return ( 0 );

  if ( k_operafan[ m ][ k ] != -1 ) ;
  else
  {
    int res = 0;

    for ( i = 0; m - c[ k ] * i >= 0; ++i )
      res = max ( res, dpFSA ( m - c[ k ] * i, k + 1 ) + p[ k ] * i );

    k_operafan[ m ][ k ] = res;
  }

  return ( k_operafan[ m ][ k ] );
}

int
main (
  int   argc,
  char *argv[ ]
  )
{
  char buf[ BUFSIZ ];
  int i;

  for ( ; ; )
  {
    int res = 0;

    if ( fgets ( buf, BUFSIZ, stdin ) == NULL )
      break ;
    sscanf ( buf, "%d%d", &n, &m );
    for ( i = 0; i < n; ++i )
    {
      fgets ( buf, BUFSIZ, stdin );
      fgets ( buf, BUFSIZ, stdin );
      sscanf ( buf, "%d%d%d%d", &c[ i ], &v[ i ], &d[ i ], &l[ i ] );
    }

    p = v;
    memset ( k_operafan, -1, sizeof ( k_operafan ) );
    res = max ( res, dpFSA ( m, 0 ) );
    p = d;
    memset ( k_operafan, -1, sizeof ( k_operafan ) );
    res = max ( res, dpFSA ( m, 0 ) );
    p = l;
    memset ( k_operafan, -1, sizeof ( k_operafan ) );
    res = max ( res, dpFSA ( m, 0 ) );

    printf ( "%d\n", res );
  }

  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 1428
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
const int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
const int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;

const int NM = 50;
ll len[NM], np[NM];

ll calc(ll n, ll x) {
    if (x == 0) return 0;
    if (n == 0) return x;
    else {
        if (x >= 1 && x <= 1+len[n-1]) return calc(n-1,x-1);
        else if (x >= 2 + len[n-1] && x <= 2+2*len[n-1])
            return np[n-1] + 1 + calc(n-1,x-2-len[n-1]);
        else if (x >= 3+2*len[n-1])
            return np[n];
    }
}


int main()
{
    ll n, x;
    cin >> n >> x;
    len[0] = 1; np[0] = 1;
    repSE(i,1,NM+1) {
        len[i] = 2*len[i-1] + 3;
        np[i] = 2*np[i-1] + 1;
    }
    ll ans = calc(n,x);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
	int n,h[101],m[101];
	int l,k[101],g[101];
	int t[201];
	int hh,mm;
	int i,j,temp;
	
	j=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&h[i],&m[i]);
		t[j]=h[i]*60+m[i];
		j++;
	}
	scanf("%d",&l);
	for(i=0;i<l;i++){
		scanf("%d %d",&k[i],&g[i]);
		t[j]=k[i]*60+g[i];
		j++;
	}
	for(i=0;i<n+l-1;i++){
		for(j=i+1;j<n+l;j++){
			if(t[i]==t[j]){
				t[i]=-1;
			}
			else if(t[i]>t[j]){
				temp=t[i];
				t[i]=t[j];
				t[j]=temp;
			}
		}
	}
	for(i=0;i<n+l-1;i++){
		if(t[i]!=-1){
			hh=t[i]/60;
			t[i]=t[i]%60;
			printf("%d:%02d ",hh,t[i]);
		}
	}
	hh=t[n+l-1]/60;
	t[n+l-1]=t[n+l-1]%60;
	printf("%d:%02d\n",hh,t[n+l-1]);
	return 0;
}

Measured memory_bytes: 1044
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(a: int, b: int, c: int):
    ret = NO
    if c - b == b - a:
        ret = YES
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    solve(a, b, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n, w, h;
    int aw[100005] = {0}, ah[100005] {0};
    cin >> n >> w >> h;
    rep(i,n){
        int x, y, l;
        cin >> x >> y >> l;
        aw[max(x - l, 0)]+=1;
        aw[min(x + l + 0, 100001)]-=1;
        ah[max(y - l, 0)]+=1;
        ah[min(y + l + 0, 100001)]-=1;
    }

    int c = 0;
    bool f = true;
    rep(i,w){
        c+=aw[i];
        if(c <= 0) f = false;
    }

    c = 0;
    rep(i,h){
        c+=ah[i];
        if(c <= 0 && not f){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 3864
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lli long long int
using namespace std;

int main() {
	fastio;
	string a, b;
	cin >> a >> b;

	int ans = 0;
	for (int i = 0; i < a.length(); ++i)
	{
		if (a[i] != b[i]) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3772
#include<iostream>
using namespace std;
long long n, m;
long long a[100000];
bool search(long long v);
int main(){

	cin >> n >> m;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	int l, r;
	l = 0; r = 100000 * 10000;
	while (r-l>1){
		long long mi = (l + r) / 2;
		if (search(mi))r = mi;
		else l = mi;
	}
		cout << r << endl;
}
bool search(long long v){
	long long n2=0, m2=0,b=0;
	while (n2 < n&&m2 < m){
		if (b + a[n2] <= v){
			b += a[n2];
			n2++;
		}
		else{
			b = 0;
			m2++;
		}
	}
	if (n2 == n&&m2 < m)return true;
	return false;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, c;
  cin >> n >> c;
  vi v(n), w(n);
  rep(i, n) cin >> v[i] >> w[i];
  vi dp(c + 1, 0);
  rep(i, n) rep(j, c) {
    if(j + w[i] <= c) dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
  }
  cout << *max_element(all(dp)) << endl;
}


Measured memory_bytes: 3140
S = input()
N = len(S)
is_strong_pal = (S == S[::-1])
is_strong_pal &= (S[:(N-1)//2] == S[:(N-1)//2:-1])
is_strong_pal &= (S[(N+3)//2-1:] == S[(N+3)//2-1:][::-1])
print('Yes' if is_strong_pal else 'No')

Measured memory_bytes: 3060
n = int(input())
x = list(map(int, input().split()))

y = sorted(x, reverse=True)
me1 = y[(n+1) // 2 - 1]
me2 = y[(n+1) // 2]
for i in range(n):
    if x[i] <= me2:
        print(me1)
    else:
        print(me2)

Measured memory_bytes: 26016
(let* ((n (read))
    (a (make-array n))
    (ans 0))
    (dotimes (i n)
        (setf (aref a i) (read))
        (if (and (zerop (rem i 2)) (not (zerop (rem (aref a i) 2))))
            (incf ans)
        )
    )
    (princ ans)
)

Measured memory_bytes: 24604
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
  int n;
  cin>>n;
  vector<int>vec(n);
  int l;
  rep(i,n){
    cin>>vec.at(i);
  }
  int ans=0;
  sort(all(vec));
  rep(i,n-2){
    rep(j,n-i-1){
      rep(k,n-i-j-2){
        //cout<<vec.at(i)<<" "<<vec.at(j+i+1)<<" "<<vec.at(k+i+j+2)<<endl;
        if(vec.at(i)==vec.at(j+i+1)||vec.at(j+i+1)==vec.at(k+i+j+2)){
          continue;
          
        }
        if(vec.at(i)+vec.at(j+i+1)<=vec.at(k+i+j+2)){
         
          continue;
        }
        ans+=1;
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Dice Dice;
struct Dice
{
	int surfaces[6];
};

Dice *
Dice_init(Dice *d, int *surfaces)
{
	int i;
	for (i = 0; i < 6; i++)
	{
		d->surfaces[i] = surfaces[i];
	}
	return d;
}

void
Dice_roll(Dice *d, char direction)
{
	int i;
	int next_surfaces[6];
	for (i = 0; i < 6; i++)
	{
		next_surfaces[i] = d->surfaces[i];
	}
	switch (direction)
	{
	case 'N':
		next_surfaces[0] = d->surfaces[1];
		next_surfaces[1] = d->surfaces[5];
		next_surfaces[5] = d->surfaces[4];
		next_surfaces[4] = d->surfaces[0];
		break;
	case 'E':
		next_surfaces[0] = d->surfaces[3];
		next_surfaces[3] = d->surfaces[5];
		next_surfaces[5] = d->surfaces[2];
		next_surfaces[2] = d->surfaces[0];
		break;
	case 'S':
		next_surfaces[0] = d->surfaces[4];
		next_surfaces[4] = d->surfaces[5];
		next_surfaces[5] = d->surfaces[1];
		next_surfaces[1] = d->surfaces[0];
		break;
	case 'W':
		next_surfaces[0] = d->surfaces[2];
		next_surfaces[2] = d->surfaces[5];
		next_surfaces[5] = d->surfaces[3];
		next_surfaces[3] = d->surfaces[0];
		break;
	}
	for (i = 0; i < 6; i++)
	{
		d->surfaces[i] = next_surfaces[i];
	}
}

int
Dice_top(Dice *d)
{
	return d->surfaces[0];
}

int
main()
{
	int i;

	int surfaces[6];
	for (i = 0; i < 6; i++)
	{
		scanf("%d", &surfaces[i]);
	}

	char directions[100];
	scanf("%s", directions);

	int n_directions;
	n_directions = strlen(directions);

	Dice d;
	Dice_init(&d, surfaces);
	for (i = 0; i < n_directions; i++)
	{
		Dice_roll(&d, directions[i]);
	}
	printf("%d\n", Dice_top(&d));

	return 0;
}

Measured memory_bytes: 596
def main():
    N, A = int(input()), list(map(int, input().split()))

    flag = True 

    for n in range(N):
        if A[n] % 2 == 0 and A[n] % 3 != 0 and A[n] % 5 != 0:
            flag = False
    
    print('APPROVED') if flag else print('DENIED') 


if __name__ == '__main__':
    main()



Measured memory_bytes: 9020
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    vector<int> l(n), r(n);
    // j - i = a[i] + a[j]
    // i + a[i] = j - a[j]
    for (int i = 0; i < n; i++) {
        l[i] = i + a[i];
        r[i] = i - a[i];
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());
    
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        auto ill = lower_bound(l.begin(), l.end(), i);
        ll llow = ill - l.begin();
        auto ilu = upper_bound(l.begin(), l.end(), i);
        ll lup = ilu - l.begin();
        
        auto irl = lower_bound(r.begin(), r.end(), i);
        ll rlow = irl - r.begin();
        auto iru = upper_bound(r.begin(), r.end(), i);
        ll rup = iru - r.begin();
        
        ans += (lup - llow) * (rup - rlow);
        
    }
    
    cout << ans << endl;
    
    return 0;
}


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

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;

int main() {
    constexpr int C_MAX = 100000;
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    REP(i, R) {
        cin >> r[i];
        --r[i];
    }
    vector<vector<pii>> g(N);
    REP(i, M) {
        int A, B, C;
        cin >> A >> B >> C;
        --A; --B;
        g[A].push_back(pii(B, C));
        g[B].push_back(pii(A, C));
    }

    const ll INF = (N << R) * C_MAX;
    int result = INF;
    int mask = (1 << R) - 1;
    REP(start, R) {
        vector<int> dp(N << R, INF);
        priority_queue<pli, vector<pli>, greater<pli>> q;
        dp[(r[start] << R) ^ (1 << start)] = 0;
        q.push(pli(0, r[start] << R ^ 1 << start));
        while (!q.empty()) {
            ll d;
            int state;
            tie(d, state) = q.top();
            q.pop();
            if (d < dp[state]) {
                continue;
            }
            int u = state >> R;
            int visited = state & mask;
            for (const pii &edge: g[u]) {
                int v = edge.first;
                int cost = edge.second;
                int k = distance(r.begin(), find(all(r), v));
                if (visited & 1 << k) {
                    continue;
                }
                int visited_next;
                if (k == R) {
                    visited_next = visited;
                } else {
                    visited_next = visited | 1 << k;
                }
                int state_next = v << R ^ visited_next;
                if (dp[state_next] > d + cost) {
                    dp[state_next] = d + cost;
                    q.push(pli(dp[state_next], state_next));
                }
            }
        }
        REP(u, N) {
            result = min(result, dp[u << R ^ mask]);
        }
    }
    cout << result << endl;

    return 0;
}

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

void trace(vector<int> A, int N) {
  for (int i = 0; i < N; i++) {
    if (i > 0) cout << ' ';
    cout << A[i];
  }
  cout << endl;
}

void insertionSort(vector<int> A, int N) {
  for (int i = 0; i < N; i++) {
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A, N);
  }
}
  
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  insertionSort(A, N);
}


Measured memory_bytes: 3128
#include <iostream>
#include <string.h>
using namespace std;

int w, h, xs, ys, xg, yg, n;
int b[101][101];
bool f[101][101];

void maze(int x, int y) {
	f[x][y] = 1;

	int cl = b[xs][ys];

	if (x < w && !f[x + 1][y] && b[x + 1][y] == cl)
		maze(x + 1, y);

	if (x > 1 && !f[x - 1][y] && b[x - 1][y] == cl)
		maze(x - 1, y);

	if (y < h && !f[x][y + 1] && b[x][y + 1] == cl)
		maze(x, y + 1);

	if (y > 1 && !f[x][y - 1] && b[x][y - 1] == cl)
		maze(x, y - 1);
}

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

	while (w != 0 || h != 0) {
		cin >> xs >> ys >> xg >> yg >> n;

		memset(b, 0, sizeof(b));
		memset(f, 0, sizeof(f));

		for (int i = 0; i < n; i++) {
			int c, d, x, y;

			cin >> c >> d >> x >> y;

			if (d) {
				for (int i = 0; i < 2; i++)
					for (int j = 0; j < 4; j++)
						b[x + i][y + j] = c;
			}
			else {
				for (int i = 0; i < 2; i++)
					for (int j = 0; j < 4; j++)
						b[x + j][y + i] = c;
			}
		}

		maze(xs, ys);

		if (f[xg][yg])
			cout << "OK" << endl;
		else
			cout << "NG" << endl;

		cin >> w >> h;
	}

	return 0;
}


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

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
} comb(1000010);

mint factorial(ll n) {
  mint t = 1;
  for (int i = 1; i <= n; i++) t *= i;
  return t;
}

int main() {
  int s;
  cin >> s;
  mint ans = 0;
  for (int i = 1; i <= s / 3; i++) {
    int t = s;
    t -= 3 * i;
    ans += comb(t + i - 1, i - 1);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
 int N;
   cin >> N;
  int count=N;
   vector<int>yama(N);
  
  for(int i=0;i<N;i++){
   cin >> yama.at(i);
  }
  
  for(int i=0;i<N;i++){
     for(int j=0;j<i;j++){
       if(yama.at(i)>=yama.at(i-j-1)){
       }
       else{
         count--;
         break;
       }
     }
  }
  
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, m, n) for(ll i = (ll)m; i < (ll)n; i++)
#define PER(i, m, n) for(ll i = (ll)m; i > (ll)n; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

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 is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    REP(i, 0, n) cin >> v[i];
    ll ans = 0;

    REP(i, 0, n-1){
        if(v[i] > v[i+1]){
            ans += v[i] - v[i+1];
            v[i+1] += v[i] - v[i+1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4756
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
小数の桁数を指定する
	cout << setprecision(8)<< mp[0]-mx << endl;
*/
	ll mp[40000][10] = {0};
	ll two[40000][100] = {0};
	ll ans[1000] = {0};

int main()
{
	ll i,j,k,a,b;//,ans=0;
	char c;
	ll N,M,T;
	string S;


	cin >> N;
	cin >> S;
	for(i=N-1;i>0;--i)
	{
		for(j=0;j<10;++j)
		{
			mp[i-1][j] = mp[i][j] | (j == S[i]-'0');
		}
	}
	for(i=N-2;i>0;--i)
	{
		for(j=0;j<100;++j)
		{
			two[i-1][j] = two[i][j] | (j/10 == S[i]-'0' && mp[i][j%10] == 1);
		}
	}
	for(i=0;i<N;++i)
	{
		for(j=0;j<100;++j)
		{
			if(two[i][j])
				ans[(S[i]-'0')*100+j] = 1;
		}
	}
	k = 0;
	for(i=0;i<1000;++i)
	{
		k += ans[i];
	}
	cout << k << endl;
	return 0;
}




















Measured memory_bytes: 27776
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include <cstring>
#include<bits/stdc++.h> 
#include<stdio.h>
using namespace std;
vector<int> p[100010];
queue<int> q;
int vis1[100010],vis2[100010],n;
void dfs()
{
    int i,j,x,y;
    q.push(1);
    q.push(0);
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        y=q.front();
        q.pop();
        for(i=0;i<p[x].size();i++)
        {
            j=p[x][i];
            if(vis1[j]==0)
            {
                vis1[j]=y+1;
                q.push(j);
                q.push(y+1);
            }
        }
    }
}
void bfs()
{
    int i,j,x,y;
    while(!q.empty())
        q.pop();
    q.push(n);
    q.push(0);
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        y=q.front();
        q.pop();
        for(i=0;i<p[x].size();i++)
        {
            j=p[x][i];
            if(vis2[j]==0)
            {
                vis2[j]=y+1;
                q.push(j);
                q.push(y+1);
            }
        }
    }
}
int main()
{
    int i,j,k,x,y;
    scanf("%d",&n);
    for(i=1;i<n;i++)
    {
        scanf("%d%d",&x,&y);
        p[x].push_back(y);
        p[y].push_back(x);
    }
    memset(vis1,0,sizeof(vis1));
    vis1[1]=-1;
    dfs();
    memset(vis2,0,sizeof(vis2));
    vis2[n]=-1;
    bfs();
    vis2[n]=-1;
    y=0;
    for(i=1;i<=n;i++)
        if(vis2[i]<vis1[i])
            y++;
        x=n-y;
        if(x>y)
            printf("Fennec\n");
        else
            printf("Snuke\n");
        return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD  998244353 // 1000000007 // //100000000
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << " "; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a/__gcd(a, b))*b; }

void solve(){
    ll n;
    string s;
    cin >> n >> s;
    ll e[n+2], w[n+2]; mem(e, 0); mem(w, 0);
    rep(i, n){
        w[i+1] = w[i] + (s[i] == 'W');
    }
    repr(i, n)
    {
        e[i+1] = e[i+2] + (s[i] == 'E');
    }
    ll ans = inf;
    for(ll i = 1; i <= n; i++){
        ans = min(ans, w[i-1] + e[i+1]);
    }
    cout << ans;
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 5396
#include <bits/stdc++.h>
using namespace std;
//DPによる解法
string divide[]={"dream","dreamer","erase","eraser"};
bool dp[100010];//i字目まで切れたら１
int main(){//切れるタイミングを確定させるために反転しておく
    string s;cin >> s;
    dp[0]=1;
    for(int i=0;i<s.size();i++){
        //printf("%d=%d\n",i,dp[i]);
        if(!dp[i]) continue;//そこまでで矛盾があればとりあえず無視
        for(string d:divide){
            if(s.substr(i,d.size())==d) dp[i+d.size()]=1;
        }
        //printf("%d=%d\n",i,dp[i]);
    }
    cout << (dp[s.size()]? "YES":"NO") << endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

ll getPrime(ll x) {
  ll res = 2;
  while (x >= res * res) {
    if (x % res == 0) {
      return res;
    }
    res++;
  }

  return res;
}

int main() {
  ll x;
  cin >> x;

  if (x == 1) {
    cout << "0 -1" << endl;
    return 0;
  }

  // ll r = getPrime(x);

  for (int a = -200; a < 200; a++) {
    for (int b = -200; b < 200; b++) {
      if ((a * a * a * a * a) - (b * b * b * b * b) == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }

  cout << "NOT FOUND" << endl;
}

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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<int,int> P;
const ll MAX_N=131072;
const ll INF=1000000;
int main(){
  int N;cin>>N;
  int ans=0;
  rep(i,N) ans+=(i+1);
  cout<<ans<<endl;
}


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

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

    vector<double> v(N);
    rep(i, N) cin >> v[i];

    rep(k, N-1) {
        vector<double> tmp(N-k-1, 0);
        sort(v.begin(), v.end());

        for (int i=0; i<N-k-1; ++i) {
            tmp[i] = v[i] + v[i+1];
        }

        double mi = 1e8;
        int idx = 0;
        rep(i, tmp.size()) {
            if (mi > tmp[i]) {
                mi = tmp[i];
                idx = i;
            }
        }

        // rep(i, tmp.size()) cout << tmp[i] << " ";
        // cout << endl;

        int cur = idx, cur2 = idx+1, n = 0;
        vector<double> v2(N-k-1);
        rep(i, v.size()) {
            if (cur == i) {
                v2[n++] = (v[i] + v[i+1]) / 2.0;
                i++;
                continue;
            }
            v2[n++] = v[i];
        }
        v = v2;
        //
        // rep(i, v.size()) cout << v[i] << " ";
        // cout << endl;
    }

    printf("%.10f\n", v[0]);

}


Measured memory_bytes: 256
r,c=gets.chomp.split(" ").map(&:to_i)
#2重リストの宣言
list=Array.new(r+1).map{Array.new(c+1)}
for i in 0..r-1 do
input=gets.chomp.split(" ").map(&:to_i)
for j in 0..c-1 do
list[i][j]=input[j]
end
list[i][c]=input.sum
end

for j in 0..c do
 sum=0
 for i in 0..r-1 do
  sum=sum+list[i][j]
 end
 list[r][j]=sum
end

for i in 0..r do
print"#{list[i].join(' ')}\n"
end 


Measured memory_bytes: 7096
// atcoder/abc178/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  lli n;
  while (cin >> n) {
    const int N = 1e6 + 5;
    const int _9 = 1;
    const int _0 = 2;
    static lli dp[N][4];
    fill(&dp[0][0], &dp[N - 1][4 - 1] + 1, 0);
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j <= 3; ++j) {
        for (int k = 0; k <= 9; ++k) {
          if (0) ;
          else if (k == 9) (dp[i + 1][j | _9] += dp[i][j]) %= mod;
          else if (k == 0) (dp[i + 1][j | _0] += dp[i][j]) %= mod;
          else (dp[i + 1][j] += dp[i][j]) %= mod;
        }
      }
    }
    cout << dp[n][_9 | _0] << endl;
  }

  return 0;
}


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

const ll MAX_N = 1e5;

int main(){
    ll n, res=0, s[MAX_N]={}, used[MAX_N]={};

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

    for (int c = 1; c <= n - 2; ++c) {
        ll f = 0;
        for (int mc = 0; c < n - 1 - mc; mc += c) {
            used[mc] = c;
            if (used[n - 1 - mc] >= c) break;
            f += s[mc] + s[n - 1 - mc];
            res = max(res, f);
        }
    }

    cout << res << endl;
    return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  string a[n],b[m];
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  
  bool ans=false;
  
  rep(i,n-m+1)rep(j,n-m+1){
    int flag = true;
    rep(k,m){
      if(b[k] != a[k+i].substr(j,m)) flag = false;
    }
    if(flag){
      ans = true;
      break;
    }
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

#pragma warning(disable : 4996)

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
//#define int long long;

double dist(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll idist(ll x1, ll y1, ll x2, ll y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

signed main() {
  ll N;
  cin >> N;
  vector<ll> list(N);
  rep(i, N) { cin >> list[i]; }
  sort(all(list));
  int c = 0;
  rep(i, N) {
    for (int j = i+1; j < N; j++) {
      for (int k = j+1; k < N; k++) {
        if (list[i] == list[j] or list[j] == list[k] or list[i] == list[k]) {
          ;
        } else if (list[i]+list[j]<=list[k]) {
          ;
        } else {
          c++;
        }
      }
    }
  }
  cout << c;
}


Measured memory_bytes: 3720
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  ll n;
  int k;
  cin >> n >> k;
  if (n <= 2) {
    cout << 0 << endl;
    return 0;
  }
  n -= 2;
  ll cnt11 = 0;
  REP(i, 0, 11) {
    REP(j, 1, 6) {
      if ((9 * (7 * i + j + 8)) % 11 == k) { cnt11++; }
    }
  }
  ll sum = 0;
  REP(i, 0, n % 11) {
    REP(j, 1, 6) {
      if ((9 * (7 * i + j + 8)) % 11 == k) { sum++; }
    }
  }
  cout << cnt11 * (n / 11) + sum << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
ll MOD = 1000000007;

int main()
{
    ll K, S;
    cin >> K >> S;
    ll count = 0;
    rep(i, K+1) {
        rep(j, K+1) {

            ll tmp = S - i - j;
            if (0 <= tmp & tmp  <= K) count++;
        }
    }
    cout << count << endl;
    return 0;
}


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

int main() {
  int n, m, x;
  cin >> n >> m >> x;

  int res = 1010101010;

  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));

  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  // {0, 1, ..., n-1} の部分集合の全探索
  for (int bit = 0; bit < (1 << n); ++bit) {
    /* bit で表される集合の処理を書く */
    int total = 0;

    /* きちんとできていることを確認してみる */
    // bit の表す集合を求める
    vector<int> S;
    for (int i = 0; i < n; ++i) {
      if (bit & (1 << i)) {  // i が bit に入るかどうか
        S.push_back(i);
      }
    }

    vector<int> p(m);

    for (int i = 0; i < (int)S.size(); ++i) {
      for (int j = 0; j < m; j++) {
        p[j] += a[S[i]][j];
      }
      total += c[S[i]];
    }
    bool ok = true;
    for (int i = 0; i < m; i++) {
      if (p[i] < x) ok = false;
    }
    if (ok) res = min(res, total);
  }
  if (res == 1010101010)
    cout << -1 << endl;
  else
    cout << res << endl;
}

Measured memory_bytes: 3628
def reroot(nodeCount, edges, identity, merge, addNode, root=0):
    adjacents = [list() for _ in range(nodeCount)]
    indexForAdjacents = [list() for _ in range(nodeCount)]
    for u, v in edges:
        indexForAdjacents[u].append(len(adjacents[v]))
        indexForAdjacents[v].append(len(adjacents[u]))
        adjacents[u].append(v)
        adjacents[v].append(u)
    childSubtreeRes = [[identity]*len(adjacents[i]) for i in range(nodeCount)]
    nodeRes = [identity]*nodeCount

    parents = [-1]*nodeCount
    order = [0]*nodeCount
    index = 0
    stack = [root]
    while stack:
        node = stack.pop()
        order[index] = node
        index += 1
        for adjacent in adjacents[node]:
            if adjacent == parents[node]:
                continue
            stack.append(adjacent)
            parents[adjacent] = node

    for node in reversed(order):
        parent = parents[node]
        result = identity
        parentIndex = -1
        for j in range(len(adjacents[node])):
            if adjacents[node][j] == parent:
                parentIndex = j
                continue
            result = merge(result, childSubtreeRes[node][j])
        if parentIndex >= 0:
            childSubtreeRes[parent][indexForAdjacents[node][parentIndex]] = addNode(result, node)

    for node in order:
        accumsFromTail = [identity]*len(adjacents[node])
        for j in range(len(adjacents[node]) - 1, 0, -1):
            accumsFromTail[j - 1] = merge(childSubtreeRes[node][j], accumsFromTail[j])
        accum = identity
        for j in range(len(adjacents[node])):
            result = addNode(merge(accum, accumsFromTail[j]), node)
            childSubtreeRes[adjacents[node][j]][indexForAdjacents[node][j]] = result
            accum = merge(accum, childSubtreeRes[node][j])
        nodeRes[node] = addNode(accum, node)
    return nodeRes

int1 = lambda x: int(x) - 1
n, mod = map(int, input().split())
merge = lambda u, v: u * v % mod
addNode = lambda val, id: val + 1
edges = [tuple(map(int1, input().split())) for _ in range(n-1)]
res = list(map(int1, reroot(n, edges, 1, merge, addNode)))
print(*res, sep='\n')

Measured memory_bytes: 65536
#include<iostream>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	long long x,y,t;
	cin>>x>>y;
	t=x;
	int len=0;
	while(t<=y)
	{
		len++;
		t<<=1;
	}
	cout<<len;
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
pair<ll, ll> a[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> a[i].f >> a[i].s;

    return true;
}

bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
    return a.f + a.s > b.f + b.s;
}

void solve() {
    sort(a, a + n, cmp);
    ll ans = 0;

    for (int i = 0; i < n; ++++i)
        ans += a[i].f + a[i].s;

    forn (i, n)
        ans -= a[i].s;

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=100007;
const long long INF=1000000009;
long long A[N],D[N];
int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;++i)
    cin>>A[i],D[i]=INF;
  D[1]=0;
  for(int i=1;i<=n;++i){
    D[i+1]=min(D[i+1],D[i]+abs(A[i]-A[i+1]));
    D[i+2]=min(D[i+2],D[i]+abs(A[i]-A[i+2]));
  }
  cout<<D[n];
}


Measured memory_bytes: 1792
n = int(input())
p = tuple(map(int,input().split()))
ans = sorted(p)
for i in range(n):
    for j in range(n):
        ori = list(p)
        temp = ori[i]
        ori[i] = ori[j]
        ori[j] = temp
        if ans == ori:
            print("YES")
            exit()
print("NO")

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

int main(){
	/*input*/
	int a, b, c; cin >> a >> b >> c; 
	/*calculation*/
	int o = 0;
	if(b >= a*c){
		o = c;
	}else{ 
		for(int i = 1; i <= c; i++){
			if((b - a*i) >= 0 && (b - a*(i+1)) <= 0){
					o = i;
			}
		}
	}
	/*output*/
	cout << o << endl; 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXHW=550;
const char yes='#';
const char no='.';
char a[MAXHW][MAXHW];
char b[MAXHW][MAXHW];
char r[MAXHW][MAXHW];

int main() {
	int H, W;
	scanf("%d%d",&H,&W);
	for(int i=0;i<H;i++)
		scanf("%s",a[i]);
	for(int i=0;i<H;i++) for(int j=0;j<W;j++) b[i][j]=no;
	for(int i=0;i<H;i++) for(int j=0;j<W;j++) r[i][j]=no;
	for(int j=0;j<W;j++)
		b[0][j]=yes;
	for(int j=0;j<W;j++)
		r[H-1][j]=yes;
	for(int i=1;i<H-1;i++)
		for(int j=0;j<W;j+=2)
			b[i][j]=yes;
	for(int i=1;i<H-1;i++)
		for(int j=1;j<W;j+=2)
			r[i][j]=yes;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			if(a[i][j]==yes)
				b[i][j]=r[i][j]=yes;
	for(int i=0;i<H;i++)
		puts(b[i]);
	puts("");
	for(int i=0;i<H;i++)
		puts(r[i]);
	return 0;
}


Measured memory_bytes: 1536
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
const int maxn = 2e4 + 5;
using namespace std;

int n,m;

int main(){
	scanf("%d %d", &n, &m);
	printf("%d\n", n * m);
	return 0;
}

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

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

  int a, b, c;
  cin >> a >> b >> c;
  if (a + b >= c) {
    cout << b + c << "\n";
  } else {
    cout << 2 * b + min(a, c - b) + 1 << "\n";
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int j,i,g;
    while(~scanf("%d%d",&i,&j))
    {
        g=i-j;
        if(g>=0)
        {
            printf("%d\n",g);
        }
        else
        {
            puts("0");
        }


    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

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

    ll X, K;
    cin >>  X >> K;

    ll tmp = 0;

while(X>K){
    tmp = X % K;
    X = tmp;
}

cout << min(X,K-X) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
#define MOD 100000007;

int conbis[3000][3000];

int conbination(int a, int b){
  if(conbis[a][b] != 0)return conbis[a][b];
  if(a == b || b == 0)return conbis[a][b] = 1;
  conbis[a][b] = (conbination(a - 1, b) + conbination(a - 1, b - 1)) % MOD;
  return conbis[a][b];
}

int main(){
  int r, c, a1, a2, b1, b2, x, y;
  scanf("%d%d%d%d%d%d", &r, &c, &a1, &a2, &b1, &b2);
  long long int ans = 1;
  x = abs(a1 - b1);
  x = min(x, r - x);
  y = abs(a2 - b2);
  y = min(y, c - y);
  if(r % 2 == 0 && r / 2 == x)
    ans *= 2;
  if(c % 2 == 0 && c / 2 == y)
    ans *= 2;
  ans *= conbination(x + y, y);
  ans %= MOD;
  printf("%lld\n", ans);
}

Measured memory_bytes: 12068