akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ll> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define FOR(i, a, b) for (ll i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (ll i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for (ll i = 0, _n = (n); i < _n; i++)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fi   first
#define se   second
#define all(a) a.begin(), a.end()
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define endl '\n'

const ll N = 3005, MOD = 1e9 + 7, H = 2e5 + 5;
ll dp[N], h, w, fac[H], n;
ii a[N];

void add(ll &a, ll b) {
	a = (a + b) % MOD;
	return;
}

void sub(ll &a, ll b) {
	a = (a - b + MOD) % MOD;
	return;
}

void mult(ll &a, ll b) {
	a = 1LL * a * b % MOD;
	return;
}

ll mul(ll a, ll b) {
	return 1LL * a * b % MOD;
}

ll modPow(ll a, ll x) {
	ll res = 1;
	while (x) {
		if (x & 1) mult(res, a);
		mult(a, a);
		x >>= 1;
	}
	return res;
}

ll inv(ll a) {
	return modPow(a, MOD - 2);
}

ll C(ll k, ll n) {
	ll ret = fac[n];
	mult(ret, inv(mul(fac[n - k], fac[k])));
	return ret;
}

int main(int argc, char const *argv[])
{
    //freopen("Y.inp","r",stdin);
	ios_base::sync_with_stdio(0); cin.tie(0);
	clock_t tStart = clock();

	cin >> h >> w >> n;
	FOR(i, 1, n) cin >> a[i].first >> a[i].second;
	fac[0] = 1;
	FOR(i, 1, H - 3) {
		fac[i] = fac[i - 1];
		mult(fac[i], i);
	}

	sort(a + 1, a + 1 + n);
	FOR(i, 1, n) {
		dp[i] = C(a[i].first - 1, a[i].second + a[i].first - 2);
		FOR(j, 1, i - 1) if (a[j].second <= a[i].second)
			sub(dp[i], mul(dp[j], C(a[i].first - a[j].first, a[i].first + a[i].second - a[j].first - a[j].second)));
	}

	ll res = C(h - 1, h + w - 2);
	FOR(i, 1, n) sub(res, mul(dp[i], C(h - a[i].first, h + w - a[i].first - a[i].second)));
	cout << res << endl;

	fprintf(stderr, "Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    ll A, B, N;
    cin >> A >> B >> N;
    ll x;
    if(B <= N) {
        x = floor(double(N - B + 1) / B) * B + B - 1;
    } else {
        x = N;
    }

    cout << floor(double(A * x) / B) - A * floor(double(x) / B) << endl;
    return 0;
}

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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N;
  cin >> N;
  vi A(N);
  i64 i, j;
  REP(0, N, i) {
    string S;
    cin >> S;
    size_t dot = S.find_first_of('.');
    if(dot == string::npos) {
      dot = sz(S);
    }

    // parse until dot
    i64 a = 0;
    REP(0, i64(dot), j) {
      a *= 10;
      a += S[j] - '0';      
    }
    // parse after dot
    REP(0, 9, j) {
      a *= 10;
      i64 pos = dot + 1 + j;
      if(pos < sz(S)) {
	a += S[pos] - '0';
      }
    }

    A[i] = a;
  }

  /*
  REP(0, N, i) {
    cout << A[i] << endl;
  }
  */

  vvi F(19, vi(19, 0));
  vi X(N), Y(N);
  REP(0, N, i) {
    i64 a = A[i];
    i64 x = 0, y = 0;
    while(a % 2 == 0) {
      a /= 2;
      x++;
    }
    while(a % 5 == 0) {
      a /= 5;
      y++;
    }
    x = min(x, 18LL);
    y = min(y, 18LL);
    F[x][y]++;

    X[i] = x;
    Y[i] = y;
  }

  vvi S(19, vi(19, 0));
  S[18][18] = F[18][18];
  REP(0, 18, j) {
    i64 y = 17 - j;
    S[18][y] = S[18][y+1] + F[18][y];
  }

  REP(0, 18, i) {
    i64 x = 17 - i;
    S[x][18] = S[x+1][18] + F[x][18];
    REP(0, 18, j) {
      i64 y = 17 - j;
      S[x][y] = S[x+1][y] + S[x][y+1] - S[x+1][y+1] + F[x][y];
    }
  }

  /*
  REP(0, 19, i) {
    REP(0, 19, j) {
      cout << F[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;

  REP(0, 19, i) {
    REP(0, 19, j) {
      cout << S[i][j] << " ";
    }
    cout << endl;
  }
  */

  i64 ans = 0;
  REP(0, N, i) {
    i64 rX = 18 - X[i];
    i64 rY = 18 - Y[i];

    i64 delta = S[rX][rY];
    if(rX <= X[i] && rY <= Y[i]) {
      delta--;
    }
    
    ans += delta;
    
    //cout << delta << endl;
  }
  //cout << ans << endl;
  cout << ans / 2 << endl;

  return 0;
}


Measured memory_bytes: 8004
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Mon Dec 17 15:05:49 2018
//
package main

import (
	"fmt"
	"strconv"
)

func num753(length int) []string {
	if length == 0 {
		return []string{""}
	}

	ret := make([]string, 0)
	for _, s := range num753(length - 1) {
		ret = append(ret, []string{"7" + s, "5" + s, "3" + s}...)
	}
	return append(ret, []string{"7", "5", "3"}...)
}

func unique(slice []string) []string {
	m := map[string]bool{}
	for _, s := range slice {
		m[s] = true
	}

	ret := []string{}
	for k := range m {
		ret = append(ret, k)
	}
	return ret
}

func filter(slice []string, f func(s string) bool) []string {
	ret := make([]string, 0)
	for _, s := range slice {
		if f(s) {
			ret = append(ret, s)
		}
	}
	return ret
}

func has753(s string) bool {
	var has7, has5, has3 bool
	for _, c := range s {
		if c == '7' {
			has7 = true
		} else if c == '5' {
			has5 = true
		} else if c == '3' {
			has3 = true
		}
	}
	return has7 && has5 && has3
}

func lessThanOrEuqal(n int) func(s string) bool {
	return func(s string) bool {
		m, _ := strconv.Atoi(s)
		return m <= n
	}
}

func main() {
	var N int
	fmt.Scan(&N)

	nums := num753(len(strconv.Itoa(N)))

	fmt.Println(len(filter(filter(unique(nums), has753), lessThanOrEuqal(N))))
}


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

ll dp[1001][1001];

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> grid(h, vector<char>(w));
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> grid[i][j];
        }
    }
    for(int i = 0; i <= h; i++) dp[i][0] = 0;
    for(int j = 0; j <= w; j++) dp[0][j] = 0;
    dp[0][1] = 1;
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            if (grid[i-1][j-1] == '#') dp[i][j] = 0;
            else dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % ll(1e9 + 7);
        }
    }

    cout << dp[h][w] << endl;

    return 0;
}

Measured memory_bytes: 9088
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - 一次元リバーシ / 1D Reversi
            var s = Console.ReadLine();

            int count = 0;
            char color = s[0];

            foreach(var c in s)
            {
                if (c != color)
                {
                    color = c;
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 11232
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
 
using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
#define SPEEDUP {cin.tie(0); ios::sync_with_stdio(false);}
#define INSIDE(i,j,H,W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
#define YesNo(b) (b ? "Yes" : "No")
#define YESNO(b) (b ? "YES" : "NO")
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;
 
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
 
// all_of
// partial_sum, adjacent_difference
 
#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#endif
 
#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif
 
LL N;
 
LL func(LL a) {
	LL sum = 0;
	while (a > 0) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
 
LL A[100001];
LL B[100001];
LL DP[100001];
 
int main() {
	cin >> N;
	while (N % 5 == 0) {
		N /= 5;
	}
	while (N % 2 == 0) {
		N /= 2;
	}
 
	LL mn = INFLL;
	REP(i, 1, 1000001) {
		LL p = func(N * i);
		if (mn > p) {
			mn = p;
		}
	}
 
	LL res = 1;
	int bnum = 0;
	REP(i, 0, N) {
		A[res] = 1;
		B[i] = res;
		res *= 10;
		res %= N;
	}
	LL ans = 0;
	LL sum = 0;
	REM(i, 0, N + 1) {
		if (A[i] >= 1 && sum + i <= N) {
			int q = (N - sum) / i;
			sum += i * q;
			ans += q;
		}
	}
	if (N == 1) ans = 1;
	Fill(DP, INF);
	REP(i, 0, N) {
		if (A[i] >= 1) {
			DP[i] = 1;
		}
	}
	int con = 0;
	REP(i, 0, N) {
		if (A[i] == 0) continue;
		int k = 0;
		REP(j, 0, N * 2) {
			DP[k] = min(DP[k], DP[(k + N - i) % N] + 1);
			k =  (k + i) % N;
		}
		con++;
		if (con >= 350) break;
	}
 
	cout << min(mn, min(ans, DP[0])) << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <cstdlib>
#include <iterator>
#include <algorithm>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int mx = a[0];
    long long ans = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i] < mx)
            ans += (mx - a[i]);
        mx = max(mx, a[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
struct circle{
  double x, y, r;
  int c;
  unordered_set<int> up, down;
};
int n;
bool dp[(1<<24)];
bool canRemove(int &state, circle &disk){
  for (auto up:disk.up){
    if((state & (1<<up)))return false;
  }
  return true;
}

void calcDP(int &state, circle *disk){
  for (int i = 0; i < n; i++) {
    if((state & (1<<i)) == 0)continue;
    if(not canRemove(state, disk[i]))continue;
    for (int j = i + 1; j < n; j++) {
      if((state & (1<<j)) == 0)continue;
      if(disk[i].c != disk[j].c)continue;
      if(not canRemove(state, disk[j]))continue;
      int next_state = state ^ (1<<i);
      next_state ^= (1<<j);
      //std::cout << "next_state:" << next_state << std::endl;
      dp[next_state] = true;
    }
  }
}
void overlap(int n, circle *disk){
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      double dx = disk[i].x - disk[j].x,
        dy = disk[i].y - disk[j].y;
      if(sqrt(dx*dx + dy*dy) + 1e-8 < disk[i].r + disk[j].r)
        disk[j].up.insert(i);
    }
  }
}
             
int main(int argc, char *argv[]){
  while(cin >> n, n){
    circle disk[n];
    for (int i = 0; i < n; i++) {
      cin >> disk[i].x >> disk[i].y >> disk[i].r >> disk[i].c;
    }
    overlap(n, disk);
    int ans = 0;
    int roop = (1<<n);
    memset(dp, false, sizeof(dp));
    dp[roop - 1] = true;
    for (int i = roop - 1; i > 0; i--) {
      if(dp[i] == false)continue;
      calcDP(i, disk);
    }
    for (int i = 0; i < roop; i++) {
      if(dp[i] == false)continue;
      ans = max(ans, n - __builtin_popcount(i));
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 19620
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
 
using namespace std;

const int MAX_N = 3010;
const int MAX_T = 3010;
 
typedef long long ll;

void chmax(ll &a, ll b){ if( a < b){ swap(a,b);}return ;}

ll dp[MAX_N][MAX_T];
pair<ll,ll> X[MAX_N];
ll A[MAX_N],B[MAX_N];

int main(){
  
  int N,T; cin >> N >> T;
  
  for(int i = 0; i < N; i++){ cin >> X[i].first >> X[i].second;}
  
  sort(X,X+N);
  //時間が短い順にソートする
  
  for(int i = 0; i < N; i++){ A[i] = X[i].first; B[i] = X[i].second;}
  
  dp[0][A[0]] = B[0];
  
  for(int i = 0; i < N-1; i++){
    for(int t = 0; t < MAX_T; t++){
      
     chmax(dp[i+1][t],dp[i][t]); //A[i+1]を食べない場合
      
     if( t+A[i+1] < MAX_T){ chmax(dp[i+1][t+A[i+1]], dp[i][t]+B[i+1]);}
      
    }
  }
  
  ll ans = 0;
  
  for(int i = 0; i < N; i++){
    for(int t = 0; t < T; t++){
      
      chmax(ans, dp[i][t]+B[i+1]); // 最後にB[i+1]をボーナスで食べられる点注意
      
    }
  }
  
  cout << ans << endl;
  
  return 0;
}
     

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())
#define UNIQUE(v) \
    SORT(v);      \
    v.resize(distance(v.begin(), unique(v.begin(), v.end())))

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

const ll md = 1e9 + 7;
ll MOD(ll x) {
    ll r = x % md;
    if (r < 0) {
        r += md;
    }
    return r;
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF DBL_MAX
// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 1e18
#define MINF -INF

void solve() {
    ll n, x, m;
    cin >> n >> x >> m;
    if (n == 1) {
        cout << x << endl;
        return;
    }
    unordered_map<ll, ll> rem2idx;
    vll pref(m + 1);

    ll sm = x;
    ll prv = x;
    rem2idx[x] = 0;
    pref[1] = x;
    bool done = true;
    ll l, r;
    ll left = n - 1;
    FOR(i, 1, n) {
        ll nxt = (prv * prv) % m;
        if (rem2idx.count(nxt)) {
            done = false;
            l = rem2idx[nxt];
            r = i;
            break;
        }
        left--;
        rem2idx[nxt] = i;
        pref[i + 1] = pref[i] + nxt;
        prv = nxt;
        sm += nxt;
    }

    if (done) {
        cout << sm << endl;
        return;
    }

    ll extra = pref[r] - pref[l];
    ll sz = r - l;
    sm += extra * (left / sz);
    ll rem = left % sz;
    sm += pref[l + rem] - pref[l];

    cout << sm << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }

    // #ifdef DEBUG
    //     for (int t = 1; t <= tt || cin.rdbuf()->in_avail(); t++) {
    //         // cout << "Case #" << t << ": ";
    //         solve();
    //     }
    // #else
    //     for (int t = 1; t <= tt; t++) {
    //         // cout << "Case #" << t << ": ";
    //         solve();
    //     }
    // #endif

    return 0;
}

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

using namespace std;
typedef long long ll;
const int N = 2e5 + 100;

int n, k;
int val[N];

int main() {
	cin >> n >> k;
	for(int i = 1;i <= n; ++i)
		cin >> val[i];
	int L = 0, R = 0;
	for(int i = 1;i <= n; ++i)
		R = max(R, val[i]);
	while(R - L > 1) {
		int mid = (L + R) >> 1;
		long long cnt = 0;
		for(int i = 1;i <= n; ++i)
			cnt += (val[i] - 1) / mid;
		if(cnt <= k) R = mid;
		else L = mid;
	}
	cout << R << endl;

	return 0;
}

Measured memory_bytes: 4368
s=input()
slen=len(s)-1
slen2=(len(s)-1)//2
iswitch=0
for i in range(slen2):
    if s[i]!=s[slen-i-1]:
        iswitch=1

if s[-1]=='1' or s[0]=='0':
    iswitch=1

if iswitch==1:
    print(-1)
else:
    if slen==1:
        print("1 1")
    elif slen==2:
        print("1 2")
        print("1 3")
    else:
        if True:
            henlist=[]
            mae=1
            jswitch=0
            for i in range(slen):
                now=i+2
                if jswitch==0:
                    if s[now-1]=='1':
                        for i in range(now-mae):
                            henlist.append([mae+i, now])
                        mae=now
                        if now>(len(s))//2:
                            jswitch=1
                    else:
                        pass
                else:
                    henlist.append([mae, now])
        for hl in henlist:
            print(hl[0], hl[1])

Measured memory_bytes: 57872
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

typedef long long LL;
int main()
{
    int n,k;

    cin >> n >> k;
    if(k==0)
    {
        cout << (LL)n*n << endl;
    }
    else
    {
        LL sum = 0;

        for(int i = k+1;i<=n;i++)
        {
            int b = i;

            sum+=n/b*(b-k);

            if(n%b>=k){
                sum+=n%b-k+1;
            }
        }

        cout << sum << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t;cin >> n >> t;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  int dp[n+1][t]={};
  int dp2[n+1][t]={};
  dp[0][0]=0;
  dp2[n][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<t;j++){
      if(j-a[i]>=0){
        dp[i+1][j]=max(dp[i][j],dp[i][j-a[i]]+b[i]);
      }
      else{
        dp[i+1][j]=dp[i][j];
      }
    }
  }
  for(int i=n;i>0;i--){
    for(int j=0;j<t;j++){
      if(j-a[i-1]>=0){
        dp2[i-1][j]=max(dp2[i][j],dp2[i][j-a[i-1]]+b[i-1]);
      }
      else{
        dp2[i-1][j]=dp2[i][j];
      }
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<t;j++){
      ans=max(ans,dp[i][j]+b[i]+dp2[i+1][t-1-j]);
    }
  }
  cout << ans << endl;
}

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

//a^n mod p
//n > 0
//#include <cmath>
long long modpow(long long a, long long n, long long p) {
  if (n == 0) return 1;
  if (n % 2 == 0) {
    long long x = modpow(a, n / 2, p);
    return x * x % p;
  }
  return a % p * modpow(a, n - 1, p) % p;
}

//モジュラ逆数
long long modinv(long long n, long long p) {
  long long a = p, u = 1, v = 0;
  while (a) {
    long long t = n / a;
    n -= t * a;
    std::swap(n, a);
    u -= t * v;
    std::swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

int main() {
  long long n, a, b, p = 1e9 + 7;
  std::cin >> n >> a >> b;
  long long ans = modpow(2, n, p) - 1;

  long long x = 1, y = 1;
  for (long long i = 0; i < std::min(a, n - a); i++) {
    x *= n - i;
    x %= p;
  }
  for (long long i = 0; i < std::min(a, n - a); i++) {
    x *= modinv(i + 1, p);
    x %= p;
  }
  for (long long i = 0; i < std::min(b, n - b); i++) {
    y *= n - i;
    y %= p;
  }
  for (long long i = 0; i < std::min(b, n - b); i++) {
    y *= modinv(i + 1, p);
    y %= p;
  }

  ans -= x + y;
  while (ans < 0) ans += p;
  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);

		//???, ?????\??????????????????
		int n = sc.nextInt();
		int m = sc.nextInt();
		int matrixA[][] = new int[m][n];
		int vectorB[] = new int[m];
		int vectorC[] = new int[n];
		
		//??????A????????????????´?
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				matrixA[j][i] = sc.nextInt();
			}
		}
		
		//????????????b????????????????´?
		for(int j = 0; j < m; j++) {
			vectorB[j] = sc.nextInt();
		}
		
		//????????????c????????????????´?
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				vectorC[i] = vectorC[i] + matrixA[j][i] * vectorB[j];
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(vectorC[i]);
		}
	}
}

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

using namespace std;

typedef long long ll;

int main() {
  ll A, B, N;
  scanf("%lld%lld%lld", &A, &B, &N);
  ll x = B - 1;
  if (N < B) x = N;
//  cerr << x << endl;
  printf("%lld\n", (ll) floor(1.0 * A * x / B) - 1ll * A * (ll) floor(1.0 * x / B));
  return 0;
}


Measured memory_bytes: 3832
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e5;
vector<int> lst[N + 5];
int depth[N + 5];

int solve(int x) {
	depth[x] = 0;
	vector<int> res;
	for(auto nx: lst[x]) res.PB(solve(nx));
	sort(res.begin(), res.end(), greater<int>());
	for(int i = 0;i < lst[x].size();i++) depth[x] = max(depth[x], res[i] + i + 1);
	return depth[x];
}

void hora(int tc) {
	int n;
	cin>>n;
	for(int i = 2;i <= n;i++) {
		int x;
		cin>>x;
		lst[x].PB(i);
	}
	cout<<solve(1)<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}


Measured memory_bytes: 15488
import math

A, B, H, M = [int(n) for n in input().split()]

theta_H = (math.pi / 6)*(H + M/60)
theta_M = (math.pi/30)*M

def to_rect(r,theta):
    return (r*math.cos(theta), r*math.sin(theta))

def dist(tuple1,tuple2):
    return math.sqrt((tuple1[0] - tuple2[0])**2 + (tuple1[1] - tuple2[1])**2)

print(dist(to_rect(A,theta_H), to_rect(B,theta_M)))

Measured memory_bytes: 9580
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int m, size_, ans;
string str;
map<string, bool> mp;

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

    cin >> m;

    while (m--) {
        cin >> str;

        size_ = str.size();
        ans = 0;

        for (int i = 1; i < size_; ++i) {
            string u, v, ru, rv;
            u = str.substr(0, i);
            v = str.substr(i, size_ - i);
            ru = u;
            rv = v;
            reverse(ru.begin(), ru.end());
            reverse(rv.begin(), rv.end());

            //cout << u << " " << v << " " << ru << " " << rv << endl;

            if (!mp[u + v]) {
                ans++;
                mp[u + v] = true;
            }
            if (!mp[u + rv]) {
                ans++;
                mp[u + rv] = true;
            }
            if (!mp[ru + v]) {
                ans++;
                mp[ru + v] = true;
            }
            if (!mp[ru + rv]) {
                ans++;
                mp[ru + rv] = true;
            }
            if (!mp[v + u]) {
                ans++;
                mp[v + u] = true;
            }
            if (!mp[v + ru]) {
                ans++;
                mp[v + ru] = true;
            }
            if (!mp[rv + u]) {
                ans++;
                mp[rv + u] = true;
            }
            if (!mp[rv + ru]) {
                ans++;
                mp[rv + ru] = true;
            }
        }

        cout << ans << endl;
        mp.clear();
    }

    return 0;
}

Measured memory_bytes: 3204
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

// fn read_vec<T: FromStr>() -> Vec<T> {
//     let mut buf = String::new();
//     std::io::stdin().read_line(&mut buf).ok();
//     buf.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
// }

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let n = s.len();
    let mut dp = vec![[0; 14usize]; n+1];
    dp[0][0] = 1;
    for i in 0usize..n {
        for j in 0usize..14usize {
            if s[i] == '?' {
                for k in 0..10 {
                    let tmp: i64 = dp[i+1][(j*10+k) % 13];
                    dp[i+1][(j*10+k) % 13] = (tmp + dp[i][j]) % 1000000007;
                }
            }
            else {
                let k: usize = s[i] as usize - 48;
                let tmp: i64 = dp[i+1][(j*10+k) % 13];
                dp[i+1][(j*10+k) % 13] = (tmp + dp[i][j]) % 1000000007;
            }
        }
    }
    println!("{}", dp[n][5]);
}

Measured memory_bytes: 16636
x,n = map(int,input().split())
a = list(map(int,input().split()))
if n == 0:
    print(x)
    exit()
ans = min(a)-1
for i in range(1,102):
    if i in a:
        continue
    if abs(x-i) < abs(x-ans):
        ans = i
print(ans)

Measured memory_bytes: 61756
#include <bits/stdc++.h> 
#include<cmath>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define nax (int)1e5+2
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n" 
#define INF (int)1e9
#define eps (long double)1e-9
using namespace std;


int main(){
	fast;
	string s;
	cin >> s;
	if(s == "ABC"){
		cout<<"ARC";
	}
	else{
		cout<<"ABC";
	}

	return 0;
}
	


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <cmath>
#include <sstream>
#include <set>  

using namespace std;

int main()
{
	string s;
	cin >> s;
	if (s == "ooo") {
		cout << 1000 << endl;
	}
	else if (s == "oox" || s == "oxo" || s =="xoo")
	{
		cout << 900 << endl;
	}
	else if (s == "xxx") {
		cout << 700 << endl;
	}
	else {
		cout << 800 << endl;
	}
	return 0;
}


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

long sccpuzzle(long X, long Y){
    if(X > Y /2){
        return Y / 2;
    }else{
        long A = X + (Y - 2 * X) / 4;
        return A;
    }
}

int main() {
    long N, M;
    cin >> N >> M;
    long Ans = sccpuzzle(N, M);
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(str, input().split()))
if n % 2 == 0:
    ki = a[::2]
    gu = a[1::2]
    gu = gu[::-1]
    ans = gu+ki
else:
    ki = a[::2]
    ki = ki[::-1]
    gu = a[1::2]
    ans = ki+gu
    
print(' '.join(ans))

Measured memory_bytes: 27044
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: u64 = iterator.next().unwrap().parse().unwrap();

    let x_max: u64 = (n as f64).sqrt() as u64;

    let mut ans = n - 1;

    let mut x: u64 = 2;
    while x <= x_max {
        if n % x != 0 {
            x += 1;
            continue;
        }
        let y: u64 = n / x;
        if x > y {
            break;
        }
        ans = min(ans, x + y - 2);
        x += 1;
    }

    return format!("{}", ans);
}

#[test]
fn test() {
    assert_eq!(
        solve(
            r"10"
        ),
        "5"
    );
    assert_eq!(
        solve(
            r"50"
        ),
        "13"
    );
    assert_eq!(
        solve(
            r"10000000019"
        ),
        "10000000018"
    );
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N, K, C;
  string S;
  cin >> N >> K >> C >> S;
  vector<int> dp(N);
  rep(i, min(C+1, N)) {
    if(S[i] == 'o') dp[i] = 1;
    else if(i)      dp[i] = dp[i-1];
    else            dp[i] = 0;
  }
  REP(i, C+1, N) {
    if(S[i] == 'o') dp[i] = max(dp[i-C-1]+1, dp[i]);
    else            dp[i] = dp[i-1];
  }
  vector<int> dp2(N);
  RREP(i, N-1, max(0, N-C-1)) {
    if(S[i] == 'o') dp2[i] = 1;
    else if(i<N-1)  dp2[i] = dp2[i+1];
    else            dp2[i] = 0;
  }
  rrep(i, N-C-1) {
    if(S[i] == 'o') dp2[i] = max(dp2[i+C+1]+1, dp2[i]);
    else            dp2[i] = dp2[i+1];
  }
  map<int, int> cnt;
  rep(i, N) {
    int tmp = dp[i] + dp2[i];
    if(!cnt.count(tmp)) cnt[tmp] = 0;
  }
  rep(i, C) {
    int tmp = dp[i] + dp2[i];
    cnt[tmp]++;
  }
  rep(i, N) {
    if(i > C) {
      int rem = dp[i-C-1] + dp2[i-C-1];
      cnt[rem]--;
    }
    if(i < N-C) {
      int add = dp[i+C] + dp2[i+C];
      cnt[add]++;
    }
    int tmp = dp[i] + dp2[i];
    if(S[i] == 'o' && tmp == K+1 && cnt[tmp] == 1) cout << i+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
int n;
const long long D=1e9+7;
long long gcd(long long x,long long y){
    if(y==0)return x;
    return gcd(y,x%y);
}
long long pow2(long long x,long long y){
    if(y%2==0)return 1;
    long long ret=pow2(x,y/2);
    return ret*ret%D*(y%2==0 ? 1: x)%D;
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    long long n,a,b;
    cin>>n>>a>>b;
    cout<<n/(a+b)*a+min(n%(a+b),a);

    return 0;
}


Measured memory_bytes: 256
#pragma GCC Optimize("Ofast")
#pragma GCC Optimize "trapv"
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 

using namespace std;
//using namespace boost::multiprecision; 

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define TC int t; cin >> t; while(t--)
#define li long int
#define ll long long
#define ull unsigned long long 
#define Vec(x) vector <x>
#define Pai(x,y) pair <x,y>
#define Map(x,y) map <x,y>
#define UMap(x,y) unordered_map <x,y>
#define Set(x) set <x>
#define Sta(x) stack <x>
#define Qu(x) queue <x>
#define DQ(x) deque(x)
#define PriorQ(x)	priority_queue <x>
#define bg begin()
#define ed end()
#define sz size()
#define ct(x) count(x)
#define len length()
#define F first
#define S second
#define Makep make_pair
#define ins(x) insert(x)
#define ers(x) erase(x)
#define endl "\n";
#define MOD 1000000007
#define PI 2*acos(0.0)
#define clr() clear()
#define fori0(n) for(int i=0;i<n;i++)
#define foriab(a,b) for(int i=a;i<b;i++)
#define mem0(x) memset(x,0,sizeof(x))
#define mem1(x) memset(x,1,sizeof(x))
#define autoit(x) for(auto it=x.beg;it!=x.ed;it++)
#define count0(x) __builtin_popcount(x)
#define ret return 
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

const ll Inf=1e9+5;



namespace funset{
bool checkvow(char x){
	return ((0x208222)>>(x&(0x1f)))&1;
	}
ll highpow2(ll x){
	return (x&~(x-1));
	}
bool chk2(ll x){
		return (x&(x-1));
	}	
}

using namespace funset;

ll n, w;
ll wei[101],val[101],dp[1001][10001];

void solve(){
	ll n;
	cin >> n;
	ll a[n];
	for(ll &x:a)
		cin >> x;
	ll mx=a[0];
	ll sum=0;
	for(ll i=0;i<n;i++){
		mx=max(a[i],mx);
		sum+=abs(mx-a[i]);
	}
	cout << sum << endl;
}

int main(){
	auto beg=clock();
	
	FAST
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	//TC
    solve();
	auto ted=clock();
	#ifndef ONLINE_JUDGE
	cout << (double)(ted-beg)/CLOCKS_PER_SEC << endl;
	#endif
	ret 0;
}

Measured memory_bytes: 5204
#include<iostream>

using namespace std;

int main(){
  int a,b,c,x;
  //a,b,cは５０以下の整数、xは５０以上２００００以下の５０の倍数
  cin >> a >> b >> c >> x;
 
  int res;
  int count=0;
  for(int i=0;i<=c;i++){
   for(int j=0;j<=b;j++){
     for(int k=0;k<=a;k++){
		res=50*i+100*j+500*k;		
        if(x==res)
          count++;    	           
      }
    }
  } 
  cout << count <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}


const vector<int> match = { 0,2,5,5,4,5,6,3,7,6 };
ll N, M;
vector<ll> vec;

vector<ll> check(const vector<ll>&x, const vector<ll>& y, ll sum) {

	ll sumX = 0, sumY = 0;
	ll cntX = 0, cntY = 0;

	rep(i, x.size()) {
		sumX += x[i] * match[vec[i]];
		sumY += y[i] * match[vec[i]];
		cntX += x[i];
		cntY += y[i];
	}

	if (sumX != sum && sumY != sum) {
		return vector<ll>(M, 0);
	}
	if (sumX == sum && sumY != sum) {
		return x;
	}
	if (sumX != sum && sumY == sum) {
		return y;
	}

	if (cntX > cntY) return x;
	if (cntX < cntY) return y;

	rep(i, x.size()) {
		if (x[i] > y[i]) return x;
		if (x[i] < y[i]) return y;
	}

	return x;

}

void solve() {

	cin >> N >> M;
	vec.resize(M);
	rep(i, M) cin >> vec[i];

	SORTL2S(ll, vec);

	vector<vector<ll>> dp(N + 1, vector<ll>(M, 0));
	vector<ll> cnt(N + 1);

	for (ll i = 1; i <= N; i++) {

		vector<ll> best(M, 0);

		rep(j, M) {

			if (i < match[vec[j]]) continue;

			vector<ll> tmp = dp[i - match[vec[j]]];
			tmp[j]++;

			best = check(best, tmp, i);

		}

		dp[i] = best;
		debug(dp[i]);
	}

	rep(i, M) {
		rep(j, dp[N][i]) cout << vec[i];
	}

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	cout << endl;
	return 0;
}


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

int main() {
    ll n;
    std::cin >> n;
    ll res = 0;
    for (int i = 1; i < 32; i++) {
        if(n%2==0){
            res += n/2/(ll)pow(5,i); 
        }else{
            std::cout << 0 << std::endl;
            return 0;
        }
        // std::cout << res << std::endl;
    }
    
    std::cout << res << std::endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

int GCD(int a,int b){
    if(a<b) swap(a,b);
    if(b==0) return a;
    else return GCD(b,a%b);
}

int main(){
    int k;cin>>k;
    ll ans=0;
    for(int a=1;a<k+1;a++){
        for(int b=1;b<k+1;b++){
            for(int c=1;c<k+1;c++){
                ans+=GCD(GCD(a,b),c);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3660
n, a, b = map(int, input().split())

if n == 1:
  if a != b:
    print(0)
  else:
    print(1)
elif n == 2:
  print(1)
else:
  if a == b:
    print(1)
  elif a > b:
    print(0)
  else:
    print((b-a) * (n-2) + 1)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< VI > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;

template < typename T > inline void input_n( vector< T > &out ) { copy_n( istream_iterator< T >( cin ), out.size(), out.begin() ); };
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) (c).begin(), (c).end()
#define AALL( a, t ) (t*)a, (t*)a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define EM emplace
#define EB emplace_back
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int solve( const int C, const int N, const int S )
{
	return C == 10 ? ( !S && !N ) : solve( C + 1, N, S ) + solve( C + 1, N - 1, S - C );
}

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

	for ( int n, s; cin >> n >> s, ( n | s ); cout << solve( 0, n, s ) << endl );

	return 0;
}

Measured memory_bytes: 1192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int k = scanner.nextInt(), s = scanner.nextInt();
			int count = 0;
			for (int x = 0; x <= Math.min(k, s); x++) {
				for (int y = Math.max(0, s - x - k); y <= Math.min(k, s - x); y++) {
					int z = s - x - y;
					if ((z >= 0) && (z <= k)) {
						count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 35796
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 2e6 + 44;
const int X[] = {1,0,-1,0,1,-1,1,-1};
const int Y[] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;

int main () {
	boost;
	long long a, b, ans = 0;
	cin >> a >> b;
	long long c = __gcd (a, b);
	for (long long i = 1 ; i * i <= c ; ++ i) {
		if (c % i == 0) {
			bool ok = 1;
			for (long long j = 2 ; j * j <= i ; ++ j) {
				if (i % j == 0) {
					ok = 0;
					break;
				}
			}
			if (ok)
				++ans;
			if (i * i == c)
				break;
			ok = 1;
			for (long long j = 2 ; j * j <= c / i ; ++ j) {
				if ((c / i) % j == 0) {
					ok = 0;
					break;
				}
			}
			if (ok)
				++ans;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline().strip

#N, Q = list(map(int, input().split()))
T = input()
ACGT = set(["A", "C", "G", "T"])
num = 0
nummax = 0
for i in range(len(T)):
	if T[i] in ACGT:
		num += 1
		nummax = max(nummax, num)
	else:
		num = 0

print(nummax)

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	ll ans=1;
	for(;y>0;y>>=1){
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;
	}
	return ans;
}

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

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		vector<int> w(n);
		rep(i,0,n)cin>>w[i];
		int dp[300][300] = {0};
		rep(i,0,n)dp[i][i]=0;
		rep(i,2,n+1){
			rep(j,0,n-i+1){
				int l=j;
				int r=j+i-1;
				if(dp[l+1][r-1]==r-l-1&&abs(w[l]-w[r])<=1){
					dp[l][r]=r-l+1;
				}else{
					int temp=0;
					rep(k,l+1,r+1){
						temp=max(temp,dp[l][k-1]+dp[k][r]);
					}
					dp[l][r]=temp;
				}
			}
		}
		cout<<dp[0][n-1]<<"\n";
	}
	return 0;
}


Measured memory_bytes: 3588
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;

#define ll long long
ll N, M, Q;
vector<vector<ll>> LIST;

void cal(ll n, ll m, vector<ll> XX)
{
    if (n == N)
    {
        LIST.push_back(XX);
        return;
    }

    for (ll i = m; i <= M; i++)
    {
        vector<ll> X2(XX.size());
        copy(XX.begin(), XX.end(), X2.begin());
        X2.push_back(i);
        cal(n + 1, i, X2);
    }
}

void solve()
{
    cin >> N >> M >> Q;
    vector<vector<ll>> ABCD;
    for (ll i = 0; i < Q; i++)
    {
        vector<ll> abcd(4);
        cin >> abcd.at(0) >> abcd.at(1) >> abcd.at(2) >> abcd.at(3);
        ABCD.push_back(abcd);
    }

    vector<ll> te;
    cal(0, 1, te);
    ll dcountmax = 0;
    for (auto A : LIST)
    {
        ll dcount = 0;
        // for (auto le : A)
        // {
        //     cout << le << " ";
        // }
        // cout << endl;

        for (auto abcd : ABCD)
        {
            if ((A.at(abcd.at(1) - 1) - A.at(abcd.at(0) - 1)) == abcd.at(2))
            {
                dcount = dcount + abcd.at(3);
            }
        }

        dcountmax = max(dcountmax, dcount);
    }

    cout << dcountmax << endl;

    // cout << LIST.size() << endl;

    // cout << N << " " << M << " " << Q << endl;
    // for (ll j = 0; j < Q; j++)
    // {
    //     for (auto le : ABCD[j])
    //     {
    //         cout << le << " ";
    //     }
    //     cout << endl;
    // }

    // for (auto la : LIST)
    // {
    //     for (auto le : la)
    //     {
    //         cout << le << " ";
    //     }
    //     cout << endl;
    // }

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 13980
#include<iostream>
#define LEN 100000
using namespace std;

int n,A[LEN];

int partition(int p,int r){
  int x =A[r];
  int i = p-1,tmp;
  for(int j = p;j<r;j++){
    if(A[j] <= x){
      i=i+1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  return i+1;
}

int main(){
  int i,q;
  cin >> n;
  for(i=0;i<n;i++) cin >> A[i];

  q = partition(0,n-1);

  for(i=0;i<n;i++){
    if(i) cout << " ";
    if(i==q) cout << "[";
    cout << A[i];
    if(i==q) cout << "]";
  }
  cout << endl;
  
  return 0;
}



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

int main(){
    int x;
    cin >> x;
    x -= 400;
    int y;
    y = 8 - x/200;
    cout << y << endl;

}

Measured memory_bytes: 3640
n = int(input())
vList = list(map(int, input().split()))
cList = list(map(int, input().split()))

# print(n)
# print(vList)
# print(cList)

vSum = 0
cSum = 0

for i in range(n):
	if vList[i] > cList[i]:
		vSum += vList[i]
		cSum += cList[i]

print(vSum - cSum)


Measured memory_bytes: 3060
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints
Q = get_int
B, C = [], []
Q.times do |i|
  B[i], C[i] = get_ints
end

hash = Hash.new(0)
sum = 0

A.each do |a|
  hash[a] += 1
  sum += a
end

Q.times do |i|
  if hash[B[i]]
    bi = hash[B[i]]
    hash[B[i]] = 0
    sum -= B[i] * bi
    hash[C[i]] += bi
    sum += C[i] * bi
  end
  puts sum
end


Measured memory_bytes: 29936
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inf (int)(2 * 1e18)

signed main(){
	int N, K, i, sum;
	scanf("%lld%lld", &N, &K);
	int *w = (int *)malloc(sizeof(int) * N);
	int *d = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld%lld", &w[i], &d[i]);
	}
	int l = 0, h, r = inf;
	while(r - l > 1){
		h = (l + r) / 2;
		sum = 0;
		for(i = 0; i < N; i++){
			if(h >= w[i]){
				sum += 1 + (h - w[i]) / d[i];
			}
		}
		if(sum < K){
			l = h;
		}
		else{
			r = h;
		}
	}
	printf("%lld\n", r);
	return 0;
}

Measured memory_bytes: 1792