akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
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>;
const int INFTY =2147483647;
int main(){
    int l;
    cin>>l;
    double q=l/3.0;
    cout<<fixed << setprecision(10)<<pow(q,3)<<endl;//setprecision(n)
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    long long Q;
    cin >> Q;
    long long  T[Q] ;
    long long  F[Q];
    string c[Q];
    int count = 0;
    for(long long i = 0;i<Q;i++){
        cin >>  T[i];
        
        if(T[i] == 1){
            if(count ==0){
            count = 1;}
            else{
                count = 0;
            }
            
        }else if(T[i] == 2){
            cin >> F[i] >> c[i];
            if((F[i] == 1 && count ==0) || (F[i]==2&&count ==1)){
                s.insert(0,c[i]);
            }else if((F[i] == 1 && count ==1) || (F[i]==2&&count ==0)){
            s.insert(s.size(),c[i]); 
           
            }
        }

    }
    
    if(count == 1){
        reverse(s.begin(),s.end());
    }
    cout <<s <<endl;
    
}


Measured memory_bytes: 14848
#include <cstdio>

using namespace std;

int main(void)
{
	int a, b, c, d, e, f;
	
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
	
	int sum = 0;
	
	sum += a + b * 5 + c * 10 + d * 50 + e * 100 + f * 500;
	
	if (sum >= 1000){
		puts("1");
	}
	else {
		puts("0");
	}
}

Measured memory_bytes: 1012
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
   int N;
   cin>>N;
   int A[2][N];
   for(int i=0;i<2;i++){
       for(int j=0;j<N;j++){
           cin>>A[i][j];
       }
   }
   int max=-1;
   for(int i=1;i<=N;i++){
           int sum=0;
           for(int k=1;k<=i;k++){
              sum+=A[0][k-1];
           }
           for(int k=i;k<=N;k++){
               sum+=A[1][k-1];
           }
           if(max<sum){max=sum;}
   }
   cout<<max<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,m,q,t,x;
    cin>>n>>m;
    stack<long long> a[n];
    for(long long i=0;i<m;i++){
        cin>>q>>t;
        if(q==0){
            cin>>x;
            a[t].push(x);
        }
        else if(q==1){
            if(!a[t].empty()){
                cout<<a[t].top()<<endl;
            }
        }
        else{
            if(!a[t].empty()){
                a[t].pop();
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 5116
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
 
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
 
//std::ios::sync_with_stdio(false);   
int a[212345];
vii vec;
 
int main(){
    std::ios::sync_with_stdio(false);
    int n,i;
    cin>>n;
    rep(i,n){
    	cin>>a[i];
    }
    int ans;
    sort(a,a+n);
    double val=a[n-1]*1.000/2;
    double mini=inf;
    rep(i,n){
    	if(abs(val-a[i])<mini){
    		mini=abs(val-a[i]);
    		ans=a[i];
    	}
    }
    cout<<a[n-1]<<" "<<ans<<endl;
    
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int K,T;
int cake[101];
int main(){
  cin>>K>>T;

  for(int i = 0; i < T; i++){
    cin>>cake[i];
  }
  sort(cake,cake+T);
 

  if(T == 1){
    cout<<cake[0]-1<<endl;
   
  }

  else if(cake[T-1] - cake[T-2] > 1){
    int sum = 0;
    for(int i = 0; i < T-1; i++){
      sum += cake[i];
    }
    if(cake[T-1]-sum-1 > 0) cout<<cake[T-1]-sum-1<<endl;
    else {cout<<'0'<<endl;}
  }
  else cout<<'0'<<endl;
  
}

Measured memory_bytes: 256
s = list(input())

n = len(s) + 1
sl = [0] * n

mins = 0
sums = 0
starti = 0
inc = False
if s[0] == '<':
    inc = True
for i in range(1, n):
    if inc == True:
        sl[i] = sl[i-1]+1
        if i == n-1 or s[i] == '<':
            sums += sl[i]
        else:
            starti = i
            sl[i] = 0
            inc = False
    else:
        if i == n-1 or s[i] == '<':
            sl[i] = sl[i-1]-1
            nums = i - starti -1
            if starti != 0 and sl[starti-1]+1 > -1* sl[i]:
                sums += sl[starti-1]+1
                sl[starti-1] = sl[starti-1]+1
            else:
                nums += 1
            sums += -1 * sl[i] * nums
            sl[i] = 0
            inc = True
        else:
            sl[i] = sl[i-1] -1
            sums += sl[i]


print(sums)

Measured memory_bytes: 94824
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ s >> p.first >> p.second; return s;}
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    int N, M; cin >>N>>M;
    vector<pii> PY(M); cin >> PY;
    vector<pii> PY_sorted(PY);
    sort(all(PY_sorted));

    map<pii, int> m;
    int x = 1;
    rep(i, M) {
        if (i != 0 && PY_sorted[i-1].first != PY_sorted[i].first) x = 1;
        m[make_pair(PY_sorted[i].first, PY_sorted[i].second)] = x;
        x++;
    }

    rep(i, M) {
        int x = m[make_pair(PY[i].first, PY[i].second)];
        printf("%06d%06d\n", PY[i].first, x);
    }
}


Measured memory_bytes: 9344
// C - K-th Substring
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	string s; int k; cin>>s>>k;
	set<string> c;
	rp(i, 0, s.size())
		rp(j, i+1, i+6)
			c.insert(s.substr(i, j-i));
	for(auto x:c)
		if(--k == 0){ cout<< x <<"\n"; break; }
}


Measured memory_bytes: 1664
import java.util.*;
class Main{
	int pow(int x,int y){
		if(y==0)
			return 1;
		if(y==1)
			return x;
		int temp=pow(x,y/2);
		if(y%2==0)
			return temp*temp;
		else
			return x*temp*temp;
	}
	public static void main(String[] args){
		Main obj=new Main();
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		System.out.println(obj.pow(a,1)+obj.pow(a,2)+obj.pow(a,3));
	}
}

Measured memory_bytes: 35728
from collections import Counter
import itertools

def solve(ah, aw, s: set):
    ahh, ahc = ah
    aww, awc = aw
    if (ahh, aww) in s:
        return ahc+awc-1
    else:
        return ahc + awc

def main():
    H, W, M = map(int, input().split())
    LH = []
    LM = []
    s = set()
    for _ in range(M):
        h, w = map(int, input().split())
        LH.append(h)
        LM.append(w)
        s.add((h,w))
    
    ch = Counter(LH)
    cm = Counter(LM)

    ahp = ch.most_common()
    awp = cm.most_common()
    th = ahp[0][1]
    tw = awp[0][1]
    #print("t=", th + tw)
    ah = []
    for x in ahp:
        if x[1] == th:
            ah.append(x)
        else:
            break
    aw = []
    for x in awp:
        if x[1] == tw:
            aw.append(x)
        else:
            break
    ans = solve(ah[0], aw[0], s)
    for x, y in itertools.product(ah, aw):
        z = solve(x, y, s)
        if z > ans:
            print(z)
            exit()
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 213224
# -*- coding: utf-8 -*-
import math
import sys
 
n, m = map(int, input().split())
 
if math.fabs(n - m) == 1:
    k = 1
elif n == m:
    k = 2
else:
    k = 0
 
print(math.factorial(n) * math.factorial(m) * k % 1000000007)

Measured memory_bytes: 5176
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#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(void) {
	int K;
	cin >> K;
	queue<ll> que;

	for (int i = 1; i <= 9; i++) que.push(i);
	ll ans;
	for (int i = 0; i < K; i++) {
		ans = que.front();
		que.pop();
		if (ans % 10 != 0) que.push(ans * 10 + ans % 10 - 1);
		que.push(ans * 10 + ans % 10);
		if (ans % 10 != 9) que.push(ans * 10 + ans % 10 + 1);
	}
	cout << ans << endl;
	return 0;
}

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

long long n;

long long solve();

int main() {
  cin >> n;

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 100000;
  for(long long i = 1; i * i <= n; ++i)
    if(n % i == 0) {
      long long l = i, r = n / i, cntl = 0, cntr = 0;
      while(l > 0) {
        ++cntl;
        l /= 10;
      }
      while(r > 0) {
        ++cntr;
        r /= 10;
      }
      ans = min(ans, max(cntl, cntr));
    }
  return ans;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(i=(j);(i)<(k);++i)
#define Y first
#define X second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

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

int main() {
	int n, m, i, j, d, res;
	while (scanf("%d%d", &n, &m) && n + m) {
		char cas[128][128];
		int cnt[128][128];
		rep(i, m)
			rep(j, n)
				cnt[i][j] = INF;
		rep(i, m)
			scanf("%s", cas[i]);
		int x, y;
		rep(i, m)
			rep(j, n)
				if (cas[i][j] == '&') {
					y = i;
					x = j;
				}
		cnt[y][x] = 0;
		cas[y][x] = '.';
		queue<pi> q;
		q.push(make_pair(y, x));
		while (!q.empty()) {
			int qsize = (int) q.size();
			rep(i, qsize)
			{
				pi now = q.front();
				q.pop();
				rep(d, 4)
				{
					int ny = now.Y + dy[d], nx = now.X + dx[d];
					if (ny < 0 || nx < 0 || ny >= m || nx >= n)
						continue;
					int cost =
							cnt[now.Y][now.X]
									+ ((cas[ny][nx] == '#'
											&& cas[now.Y][now.X] != '#') ? 1 : 0);
					if (cnt[ny][nx] <= cost)
						continue;
					cnt[ny][nx] = cost;
					q.push(make_pair(ny, nx));
				}
			}
		}

		res = INF;
		rep(i, m)
		{
			res = min(res, cnt[i][0]);
			res = min(res, cnt[i][n - 1]);
		}
		rep(i, n)
		{
			res = min(res, cnt[0][i]);
			res = min(res, cnt[m - 1][i]);
		}
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;


int dp[10001]={};

int main(){
	int N,W,v[110]={},w[110]={};
	cin>>N>>W;
	rep(i,0,N) cin>>v[i]>>w[i];
	rep(i,0,N){
		for(int j=W;j>=w[i];j--){
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	o(dp[W]);
}

Measured memory_bytes: 1200
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

ll facs[5005];
ll ifacs[5005];
const int MOD = 1000000007;
ll modpow(ll b, ll e, ll m) {
  ll r = 1;
  while(e) {
    if(e%2) {
      r*=b;
      r%=m;
    }
    b*=b;
    b%=m;
    e/=2;
  }
  return r;
}
ll choose(int n, int k) {
  ll ret = facs[n];
  ret *= ifacs[k];
  ret %= MOD;
  ret *= ifacs[n-k];
  ret %= MOD;
  return ret;
}

ll partition(int n, int k) {
  if(k < 0) return 0;
  // x_1 + ... + x_n = k
  return choose(k+n-1, n-1);
}

void solve() {
  facs[0] = 1;
  for(int i = 1; i <= 5000; i++) {
    facs[i] = i * facs[i-1];
    facs[i] %= MOD;
  }
  ifacs[5000] = modpow(facs[5000], MOD-2, MOD);
  for(int i = 4999; i >= 0; i--) {
    ifacs[i] = ifacs[i+1] * (i+1);
    ifacs[i] %= MOD;
  }
  int n, k;
  cin >> n >> k;
  for(int i = 1; i <= k; i++) {
    // k+1 variables, k-1 of which must be at least one
    // x_1 + ... + x_p = n-k
    // number of (k+1) variable sums to n-2*k+1
    ll redScale = partition(i+1, n-k-(i-1));
    // i variables sum to k
    ll blueScale = partition(i, k-i);
    cout << (redScale * blueScale) % MOD << "\n";
  }
}


void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


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

int main(){
	int n;
	int sum=0;
	cin >> n;
	int a[n];
	int max=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	
	for(int i=0;i<n;i++){
		if(a[i]>max){
			max = a[i];
		}
	}
	
	for(int i=0;i<n;i++){
		sum+=a[i];
	}
	
	if(max<sum-max){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
}

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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

struct UnionFind {
    vector<int> par, treesize;
    int groups;
    
    UnionFind(int n){
        rep(i, n) par.push_back(i);
        treesize = vector<int>(n,1);
        groups = n;
    }
    
    int root(int x){
        if(x == par.at(x)) return x;
        return par.at(x) = root(par.at(x));
    }
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void unite(int x, int y){
        if(same(x,y)) return;
        int rx = root(x), ry = root(y);
        treesize[ry] += treesize[rx];
        treesize[rx] = 0;
        groups--;
        par.at(rx) = ry;
    }
};

signed main(){
    int n, m;
    cin >> n >> m;
    vector<intpair> edges(m);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        edges[i] = {a-1, b-1};
    }
    
    int ans = 0;
    rep(ignore, m){
        UnionFind uf(n);
        rep(i, m){
            if(i == ignore) continue;
            auto p = edges[i];
            uf.unite(p.first, p.second);
        }
        if(uf.groups != 1) ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 998244353LL
#define PI 3.141592653589793
#define endl "\n"

struct COM{
  ll modpow(ll x, ll nn){
    ll res = 1;
    while(nn > 0){
      if(nn & 1) res = res * x % MOD;
      x = x * x % MOD;
      nn >>= 1;
    }
    return res;
  }
  vll fact, ifact;
  COM(ll n): fact(n+1), ifact(n+1){
    assert(n < MOD);
    fact[0] = 1LL;
    for(ll i = 1; i <= n; i++) fact[i] = fact[i-1]*i%MOD;
    ifact[n] = modpow(fact[n], MOD-2);
    for(ll i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i%MOD;
  }
  ll operator()(int n, int k){
    if(k < 0 || k > n) return 0;
    return fact[n]*ifact[k]%MOD*ifact[n-k]%MOD;
  }
};

ll modbeki(ll x, ll n){
  ll res = 1LL;
  while(n > 0){
    if(n & 1){
      res *= x % MOD;
      res %= MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return res % MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  COM c(1000000);
  ll N, M, K;
  cin >> N >> M >> K;
  ll ans = 0LL;
  for(int i = 0; i <= K; i++){
    ll num = c(N-1, i);
    num *= M % MOD;
    num %= MOD;
    num *= modbeki(M-1, N-i-1);
    num %= MOD;
    ans += num;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 18720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;
	string S;
	cin >> S;

	int kazu = 0;

	int temp = 0;
	int worst = 0;

	rep(i, S.size()) {
		if (S[i] == '(') {
			kazu++;
			temp++;
		}
		else {
			temp--;
		}
		worst = min(worst, temp);
	}

	kazu = kazu * 2 - S.size();

	if (kazu < 0) worst -= kazu;

	string Smae, Sato;

	if (kazu < 0) rep(i, -kazu) Smae += "(";
	if (kazu > 0) rep(i, kazu) Sato += ")";
	if (worst < 0) {
		rep(i, -worst) Smae += "(";
		rep(i, -worst) Sato += ")";
	}

	co(Smae + S + Sato);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

const int MOD = 1e9+7;

int main(){

    string S;
    cin >> S;

    int L = (int)S.size();

    vector<int> ten(L);
    ten[0] = 1;
    for(int i = 1; i < L; i++){
        ten[i] = (ten[i - 1] * 10) % 13;
    }

    vector<vector<int>> dp(L + 1, vector<int>(13, 0));
    dp[0][0] = 1;
    for(int i = 1; i <= L; i++){
        if(S[i - 1] == '?'){
            for(int j = 0; j < 10; j++){
                for(int k = 0; k < 13; k++){
                    int num = j;
                    int next = (k + (num * ten[L - i]) % 13) % 13;
                    dp[i][next] = (dp[i][next] + dp[i - 1][k]) % MOD;
                }
            }
        }
        else{
            int num = S[i - 1] - '0';
            for(int j = 0; j < 13; j++){
                int next = (j + (num * ten[L - i]) % 13) % 13;
                dp[i][next] = (dp[i][next] + dp[i - 1][j]) % MOD;
            }
        }
    }

    // for(int i = 0; i <= L; i++){
    //     for(int j = 0; j < 13; j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dp[L][5] << endl;

    return 0;
}

Measured memory_bytes: 9344
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void yes(bool c) { if (c)print("Yes"); else print("No"); };

ll func(ll x){
    return x*(x+1)/2;
}

void solve() {
    ll n; cin >> n;
    ll left = 1;
    ll right = n;
    ll mid = (left+right)/2;
    ll ex = 0;
    while(left < right){
        // if(left>=right) break;
        mid = (left+right)/2;
        // DEBUG(left);
        // DEBUG(right);
        // DEBUG(mid);
        // DEBUG(func(mid));

        if(func(mid) <= n){
            left = mid+1;
        }else{
            right = mid;
        }
        
    }
    ex = func(left)-n;
    rng(i,1,left+1){
        if(i!=ex){
            print(i);
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int n, y;
    std::cin >> n >> y;
    for(int i = 0; i <= (y/10000); i++){
        for(int j = 0; j <= ((y-i*10000)/5000); j++){
            int k = (y-i*10000-j*5000)/1000;
            if((i+j+k) == n){
                std::cout << i << ' ' << j << ' ' << k << std::endl;
                return 0;
            }
        }
    }
    std::cout << "-1 -1 -1" << std::endl;
}


Measured memory_bytes: 256
#line 1 "/workspaces/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

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

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

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "abc171_a.cpp"

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

  char s;
  cin >> s;

  if (0 <= s - 'A' && s - 'A' < 26) {
    cout << "A" << endl;
  } else {
    cout << 'a' << endl;
  }
  return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    for (auto n: a) {
        if (n % 2) {
            cout << "first" << endl;
            return 0;
        }
    }

    cout << "second" << endl;
}


Measured memory_bytes: 640
#include<vector>
#include<iostream>
#include<functional>
#include<algorithm>

using namespace std;

int Q;
vector<long long int> A, B;

long long int SQR(long long int  a, long long int b)
{
	long long int min, med, max;
	min = 1; max = (long long int) (a + b+1) / 2;

	for (;;) {
		med = (min + max) / 2;
		//cout << med << endl;
		if ((1.0L*med*med <= a*b) && (1.0L*(med + 1.0L)*(med + 1.0L) > a*b)) { return med; }
		else if (1.0L*med*med > a*b) { max = med; }
		else if (1.0L*(med + 1.0L)*(med + 1.0L) <= a*b) { min = med + 1; }
	}

	return -999;

};

int main(void) {
	cin >> Q;

	long long int tmp;

	for (int i = 0; i < Q; i++) {
		cin >> tmp; A.push_back(tmp); cin >> tmp; B.push_back(tmp);
	}

	for (int i = 0; i < Q; i++) {

	//	if (A[i] == B[i]) { cout << 2 * A[i] - 1 << endl; continue; }

	/*	long long int p;
		long long int q;
		long long int ans = 0;
		p = 1000000000; //if (p <= A[i] * B[i]) { p = A[i] * B[i]; }
		for (q = 1; q <= 1000000000; q++) {
			if (q == B[i]) { continue; }
			long long int u;
			for (u = p - 1; u >= 1; u--) {
				if (u*q < (A[i] * B[i])) { break; }
			}
			p = u; if (p == A[i]) { p--; }

			//cout << p << endl;
			if (p <= 0) { break; }
			if (p >= 1 && p*q < A[i] * B[i]) { ans++; }

			//if (q % 1000 == 0) { cout << q << endl; }
		}
	
		cout << ans << endl;*/

		long long int val = SQR(A[i], B[i]);
		long long int wal;
		wal = A[i] * B[i] / val;
		//cout << "val= " <<val <<"  wal= " << wal<< endl;

		long long int ans;
		
		if (val*val == A[i] * B[i]) { ans = 2 * (val - 1);
		if (val > A[i] || val > B[i]) { ans--; }
		                            }
		else { 
			if (val*wal == A[i] * B[i]) { wal--; }
			if (val == wal) { ans = 2 * val - 1; }
			else { ans = 2 * val; }
			if (val >= A[i] || val >= B[i]) { ans--; }
			 }
		
		cout << ans << endl;

	}// Q-loop

	
	

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct { int parent, left, right;} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL)
    h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL)
    h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

// 接点 u の兄弟を返す
int getSibling(int u) {
  if( T[u].parent == NIL ) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left  != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
  
  if(T[u].parent == NIL) {
    printf("root\n");
  } else if(T[u].left == NIL && T[u].right == NIL) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main(void) {
  int v, l, r, root = 0;
  scanf("%d",&n);
  for(int i=0;i<n;i++) T[i].parent = NIL;
  for(int i=0;i<n;i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].left  = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }
  
  for(int i=0; i<n; i++)
  if(T[i].parent == NIL) root = i;
  
  setDepth(root,0);
  setHeight(root);
  
  for(int i=0;i<n;i++) print(i);
  
  return 0;
}



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

using namespace std;

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

  if(a==b && a==c)
    cout << "1" << endl;

  else if(a != b && a != c && b!= c)
    cout << "3" << endl;

  else
    cout << "2" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int next[300000];
int first[300000];
int go[300000];
int h[300000];
	int n,m,i,ans=0,x,y;
int check(int k){
	int t=first[k];
	int flag=1;
	while (t!=0){
		if (h[go[t]]>=h[k])
		  flag=0;
		t=next[t];
	}
   if (flag==1) return 1;else return 0;
}
int main(){

	scanf("%d %d",&n,&m);
	for (i=1;i<=n;i++)
	  scanf("%d",&h[i]);
	for (i=1;i<=m;i++)
	{scanf("%d %d",&x,&y);
	 next[i]=first[x];
	 first[x]=i;
	 go[i]=y;
	 next[i+m]=first[y];
	 first[y]=i+m;
	 go[i+m]=x;
	}
	for (i=1;i<=n;i++)
	  if (check(i)==1)
	    ans++;
	printf("%d",ans);
}

Measured memory_bytes: 4092
//グローバル変数定義
var N = 0;
var A = 0;
var B = 0;
var C = 0;
var T = [];	//N本の竹の長さを配列BBに格納する

function FullSearch(){
  const BA = 1;
  const BB = 2;
  const BC = 3;
  
  //回答格納用。初期値はinfとする。
  var LastMP = Infinity;
  
  for(var i=0 ; i<Math.pow(2,N*2) ; i++ ){
    var ans0 = 0; //何にも使わない
    var ansA = 0; //A用回答
    var cntA = 0; //A用カウンタ
    var ansB = 0; //B用回答
    var cntB = 0; //B用カウンタ
    var ansC = 0; //C用回答
    var cntC = 0; //C用カウンタ
    
    for(var j=0 ; j<N ; j++){
      //BIT積による判定処理
      switch (i & (BC<<(j*2))){
        case BA<<(j*2):
          ansA += T[j];
          cntA++;
          break;
        case BB<<(j*2):
          ansB += T[j];
          cntB++;
          break;
        case BC<<(j*2):
          ansC += T[j];
          cntC++;
          break;
        default:
          ans0 += T[j];
          break;
      }
    }
    
    //A～Cのどれにも竹が割りあたっていない場合はスキップ
    if(cntA*cntB*cntC > 0){
      //使用MP計算処理
      var MP = 0;
      //A用
      MP += Math.abs(ansA-A);
      MP += 10 * ( cntA -1 );
      //B用
      MP += Math.abs(ansB-B);
      MP += 10 * ( cntB -1 );
      //C用
      MP += Math.abs(ansC-C);
      MP += 10 * ( cntC -1 );
      //MPの記録
      if( LastMP > MP ){
        LastMP = MP;
      }
    }
  }
  return LastMP;
}
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  N = Number.parseInt(inputStr[0]);
  A = Number.parseInt(inputStr[1]);
  B = Number.parseInt(inputStr[2]);
  C = Number.parseInt(inputStr[3]);
  //N本の竹の長さを配列BBに格納する
  for( var i=0 ; i<N ; i++ ){
    T.push(Number.parseInt(input[i+1].split(" ")));
  }
  //Bit全探索で探索処理を組む
  console.log(FullSearch());
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
function main(input) {
  const args = input.split('\n');
  const N = parseInt(args[0], 10);
  let words = [];
  let ans = 'Yes';
  let pre_w;
  
  for (let i = 1; i < args.length -1; i++) {
    last_w = args[i].slice(args[i].length - 1);
    first_w = args[i].slice(0, 1);
    
    if (!pre_w) {
      words.push(args[i]);
      pre_w = last_w;
      isFirst = false;
    } else {
      if (pre_w === first_w) {
        if (!words.includes(args[i])) {
          words.push(args[i]);
          pre_w = last_w;
        } else {
          ans = 'No';
          break;
        }
      } else {
        ans = 'No';
        break;
      }
    }
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29596
def examB():
    N = I()
    A = LI(); B = LI()
    dif = sum(B) -sum(A)
    cur = 0
    for i in range(N):
        if A[i]>=B[i]:
            cur += A[i]-B[i]
        elif (A[i]-B[i])%2==1:
            cur +=1
    if dif>=cur:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}
const int n_max = 5005;
const int k_max = 5005;

signed main(){
    int n,k;
    cin >> n >> k;
    int A[n];
    REP(i,n) cin >> A[i];
    int hituyou = 0;
    int dp[2][k_max];
    REP(i,2) REP(j,k_max) dp[i][j] = 0;
    dp[0][0] = 1;
    REP(i,n){
        REP(j,k+1){
            dp[(i+1) %2][j] = dp[i %2][j];
            if(j - A[i] >= 0) dp[(i+1) %2][j] += dp[i%2][j-A[i]];
            dp[(i+1)%2][j] %= MOD;
        }
    }
    int dp2[k_max];
    REP(i,n){
        if(A[i] >= k){
            hituyou ++;
            continue;
        }
        REP(j,k + 1) dp2[j] = 0;
        REP(j,k+1){
            if(j - A[i] < 0) dp2[j] = dp[n%2][j];
            else dp2[j] = dp[n%2][j] - dp2[j - A[i]] + MOD;
            dp2[j] %= MOD;
            
            if(k - A[i] <= j and j < k and dp2[j] != 0){
                hituyou ++;
                break;
            }
        }
    }
    cout << n - hituyou << endl;


}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long dp[n][n];
    for(long long i = 0; i < n; i++) {
        for(long long j = 0; j < n; j++) {
            dp[i][j] = 0;
        }
    }
    for(int l = n - 1; l >= 0; l--)
    {
        for(int r = l; r < n; r++)
        {
            if(l == r)
                dp[l][r] = a[l];
            else
            {
                dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
            }
        }
    }
    printf("%lld\n", dp[0][n - 1]);
    return 0;
}


Measured memory_bytes: 70528
from itertools import combinations

n = int(input())
d = [0] * 5

for _ in range(n):
    s = input()
    if s[0] == "M":
        d[0] += 1
    if s[0] == "A":
        d[1] += 1
    if s[0] == "R":
        d[2] += 1
    if s[0] == "C":
        d[3] += 1
    if s[0] == "H":
        d[4] += 1

d = [n for n in d if n !=0]

comb = combinations(d, 3)
ans = 0
for c in comb:
    ans += c[0]*c[1]*c[2]

print(ans)

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

struct StAnsHis
{
  StAnsHis() : m_nProblmNo(0), m_sJudge("") { }

  int    m_nProblmNo;
  string m_sJudge;
};

void fnInput(int& rnProblmSiz, vector<StAnsHis>& rvoAnsHis)
{
  int nSubmitSiz;
  cin >> rnProblmSiz >> nSubmitSiz;
  rvoAnsHis.resize(nSubmitSiz);

  for(StAnsHis& roAnsHis : rvoAnsHis)
    cin >> roAnsHis.m_nProblmNo >> roAnsHis.m_sJudge;
}
  
void fnAnserCheck(int nProblmSiz, const vector<StAnsHis>& cnrvoAnsHis, 
                 int& rnRightAns, int& rnPenalty)
{
  vector<int> vnWACnt(nProblmSiz + 1);
  set<int> stRightAns;

  rnRightAns = 0;
  rnPenalty = 0;

  for (StAnsHis oAnsHis : cnrvoAnsHis)
  {
    if (oAnsHis.m_sJudge == "AC")
      stRightAns.insert( oAnsHis.m_nProblmNo );
    else
      if (!stRightAns.count( oAnsHis.m_nProblmNo ))
        vnWACnt[ oAnsHis.m_nProblmNo ]++;
  }

  rnRightAns = stRightAns.size();

  for (int nRightAns : stRightAns)
    rnPenalty += vnWACnt[nRightAns]; 
}
  
int main()
{
  int nProblmSiz;
  vector<StAnsHis> voAnsHis;
  fnInput(nProblmSiz, voAnsHis);

  int nRightAns, nPenalty;
  fnAnserCheck(nProblmSiz, voAnsHis, nRightAns, nPenalty);

  cout << nRightAns << " " << nPenalty;
  return 0;
}

Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+7;

int n,k;
int main(){
    cin>>n>>k; bool fl=0;
    //k|(a+b), k|(a+c), k|(b+c)  a>b>c
    //k|2*(a+b+C)
    //k|(a+b+c)    (k/2)|(a+b+c)
    ll ans=0,res=0;
    if(k==2||k==1)
    {
        if(k==1) {
            cout<<1ll*n*n*n;
        }
        else if(k==2)
        {
            int a=n/2;
            int b=n-a;
            cout<<1ll*a*a*a+1ll*b*b*b;
        }
    }else
    {
        if(k&1)
        {
            cout<<1ll*(n/k)*(n/k)*(n/k);
        }
        else
        {
            //54872+
            int kk=k/2;
            kk=n/kk;
            int a=kk/2;
            int b=kk-a;
            cout<<1ll*a*a*a+1ll*b*b*b;
        }
    }

    return 0;
}
//6 5 4 3 2 1
//5 3 1 -1 -)

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef pair<P,int> PI;

int n,m,s;
ll dp[51][10001];
vector<PI> G[51];
int c[51],d[51];

int main(void){
	scanf("%d%d%d",&n,&m,&s);
	for(int i=0;i<m;i++){
		int u,v,a,b;
		scanf("%d%d%d%d",&u,&v,&a,&b);
		u--;
		v--;
		G[u].push_back(PI(P(v,a),b));
		G[v].push_back(PI(P(u,a),b));
	}
	for(int i=0;i<n;i++){
		scanf("%d%d",&c[i],&d[i]);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<=10000;j++){
			dp[i][j]=1LL<<50;
		}
	}
	dp[0][min(10000,s)]=0;
	priority_queue<PI,vector<PI>,greater<PI> > que;
	que.push(PI(P(0,0),min(10000,s)));
	while(que.size()){
		PI p=que.top();
		que.pop();
		int v=p.first.second;
		int nc=min(10000,p.second+c[v]);
		if(dp[v][nc]>dp[v][p.second]+d[v]){
			dp[v][nc]=dp[v][p.second]+d[v];
			que.push(PI(P(dp[v][nc],v),nc));
		}
		for(int i=0;i<G[v].size();i++){
			int nv=G[v][i].first.first;
			if(p.second>=G[v][i].first.second){
				int nc=p.second-G[v][i].first.second;
				ll nd=dp[v][p.second]+G[v][i].second;
				if(dp[nv][nc]>nd){
					dp[nv][nc]=nd;
					que.push(PI(P(nd,nv),nc));
				}
			}
		}
	}
	for(int i=1;i<n;i++){
		ll ans=dp[i][0];
		for(int j=0;j<=10000;j++){
			ans=min(ans,dp[i][j]);
		}
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 19392
#include<bits/stdc++.h>
using namespace std;
#define w(t) int t;cin>>t;while(t--)
#define pb   push_back
#define mk   make_pair
#define u_s  unordered_set
#define endl "\n"
#define prDouble(x) cout<<fixed<<setprecision(10)<<x
#define ll long long int
#define ipair pair<int,int>
#define all(x) (x).begin(), (x).end()

const int mod=pow(10,9)+7;

bool compare(pair<int,int>p1,pair<int,int>p2){
    return p1.second<p2.first;
}
void open_file(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
void fast_io(){
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
      
}
/*
  ll C(ll n,ll k){
  
  if(k>n)return 0;
  
  ll ans=1;

  if(k>n-k)
    k=n-k;
  for(ll i=1;i<=k;i++)
    ans*=(n-i+1),ans/=i;

  return ans;
  }
  unsigned long long fact(long long a)
  {
  unsigned long long res=1;
  for(long long i=a;i>0;i--)
    res*=i;
  return res;
  }
  unsigned long long comb(long long a,long long b)
  {
  if((a-b)<b) b=a-b;
  if(a<=19) return fact(a)/(fact(a-b)*fact(b));
  if(a==b||b==0) return 1;
  if(b==1) return a;
  return comb(a-1,b-1)+comb(a-1,b);
  }
*/

ll dp[3005][3005];

ll game(vector<int>&A,int i,int j){

   if(i>j)return 0;

   if(dp[i][j]!=-1)return dp[i][j];

   ll way1=A[i]+min(game(A,i+2,j),game(A,i+1,j-1));
   ll way2=A[j]+min(game(A,i+1,j-1),game(A,i,j-2));
   return dp[i][j]=max(way1,way2);
}

void solve(){
   
   memset(dp,-1,sizeof dp);

   int n; cin>>n;
   ll sum=0;
   vector<int>A(n); for(int i=0;i<n;i++)cin>>A[i],sum+=A[i];

   ll X=game(A,0,n-1);
   ll Y=sum-X;

   cout<<X-Y;
}

int main(){

  //open_file();
  fast_io();
  
  solve();
  
  return 0;  
    
}


Measured memory_bytes: 74288
use std::collections::*;
use std::cmp::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        r: f64
    };
    println!("{}", 2.*r*3.141592);
}


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

typedef long long ll;
typedef unsigned long long ull;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}



const ull prime=1000000007;
// 文字列のrolling hashをコンストラクタに渡された素数と
// 渡された文字列により計算し、getRollingHashでそれを戻す
class RollingHash{
private:
    ull p[1001];
    ull ary[1001];
    int N;// 文字列長
public:
  RollingHash(const string &str){
    N=str.size();
    // prime**iを計算
    // ハッシュ値を計算
    ary[0]=0;
    for(int i=1;i<=N;i++)
        ary[i]=ary[i-1]*prime+str[i-1];
    p[0]=1;
    for(int i=1;i<N+5;i++)
        p[i]=p[i-1]*prime;
  }
    RollingHash(){}
  // 先頭をx,終端をyで指定し、その範囲のハッシュ値を取り出す
  ull getHash(const int x,const int y)const{
    return ary[y+1]-ary[x]*p[y-x+1];
  }
  // 自身の[x1,y1]の範囲でのハッシュ値と
  // rの[x2,y2]の範囲のでのハッシュ値が一致するか調べる
  bool isMatch(const int x1,const int y1,const int x2,const int y2,const RollingHash &r)const{
    return this->getHash(x1,y1)==r.getHash(x2,y2);
  }
};


int N;
string field[301];
RollingHash rhs[301];
RollingHash chs[301];

int main(){


    fastStream();
    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> field[i];

    int ans = 0;
    for(int i = 0; i < N; i++)
        rhs[i] = RollingHash(field[i]);

    for(int A = 0; A < N; A++){

        for(int j = 0; j < N; j++){
            string s;
            for(int k = 0; k < N; k++)
                s += field[(k + A) % N][j];
            chs[j] = RollingHash(s);
        }
        
        {
            bool ok = true;
            for(int k = 0; k < N; k++){
                if(rhs[(k + A) % N].getHash(0, N-1) != chs[k].getHash(0, N-1)){
                    ok = false;
                }
            }
            ans += ok;
        }

        for(int B = 1; B < N; B++){
            bool ok = true;
            int idx = (N-B);
            for(int i = 0; i < N; i++){
                if(!(rhs[(i + A) % N].getHash(0, N-1-B) == chs[idx].getHash(B, N-1)
                     && rhs[(i + A) % N].getHash(N-B, N-1) == chs[idx].getHash(0, B-1))){
                    ok = false;
                    break;                    
                }
                idx++;
                if(idx >= N)idx -= N;
            }
            ans += ok;
        }
    }
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 9728
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define pf printf
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "

using namespace std;
///check n=1;
///check corner case;

int main()
{
   ll n,i,j=0,cc=0;
   cin>>n;
   ll ara[n];
   for(i=0;i<n;i++){
    cin>>ara[i];
    if(ara[i]%2==0){
        cc++;
        if(ara[i]%3==0 || ara[i]%5==0)j++;
    }

   }
   if(j==cc)cout<<"APPROVED"<<endl;
   else cout<<"DENIED"<<endl;
return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var L, R int
	fmt.Scan(&L, &R)

	R = min(R, L+2019*2)
	ans := 2018
	for i := L; i <= R-1; i++ {
		for j := i + 1; j <= R; j++ {
			m := i * j % 2019
			ans = min(ans, m)
		}
	}
	fmt.Println(ans)
}


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

int main() {
  string S;
  cin >> S;

if (S.at(2) == S.at(3) && S.at(4) == S.at(5)){
  cout << "Yes" << endl;
}
  
  else{
    cout << "No" <<endl;
  }
}


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

int main() {
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for (auto& e : v) std::cin >> e;

    v.erase(std::unique(v.begin(), v.end()), v.end());

    for (int i = 0; i < v.size(); ++i) {
        std::cout << v[i] << " \n"[i == v.size() - 1];
    }
}



Measured memory_bytes: 3096