akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int a, b, c, k;

  cin >> a >> b >> c >> k;

  while(b <= a) { b *= 2; k--; }

  while(c <= b) { c *= 2; k--; }

  if(k >= 0) cout << "Yes\n";
  else cout << "No\n";

  return 0;
}
/*

*/


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int>edge[200005];
vector<int>vt[2], num[3];
int col[200005], ans[200005];

int main(){
	cin >> n;
	for(int i=0;i<n-1;i++){
		int a,b; cin >> a >> b;
		edge[a].emplace_back(b);
		edge[b].emplace_back(a);
	}
	function<void(int,int,int)> dfs = [&](int v,int u,int c){
		col[v] = c; vt[c].emplace_back(v);
		for(auto at:edge[v]) if(at != u) dfs(at,v,c^1);
	};
	dfs(1,-1,0);
	
	for(int i=1;i<=n;i++) num[i%3].emplace_back(i);
	for(int mask=0;mask<4;mask++){
		int x = 0, y = 0;
		for(int i=0;i<2;i++) if(((mask>>i)&1)) x += num[1+i].size();
		y = n - x - num[0].size();
		
		if(x <= vt[0].size() && y <= vt[1].size()){
			int nxt,sz = 0;
			nxt = 0;
			for(int i=0;i<2;i++) if(((mask>>i)&1)) {
				for(auto at:num[1+i]) ans[vt[0][nxt++]] = at;
			}
			while(nxt < vt[0].size()) ans[vt[0][nxt++]] = num[0][sz++];
			
			nxt = 0;
			for(int i=0;i<2;i++) if(!((mask>>i)&1)) {
				for(auto at:num[1+i]) ans[vt[1][nxt++]] = at;
			}
			while(nxt < vt[1].size()) ans[vt[1][nxt++]] = num[0][sz++];
			assert(sz == num[0].size());
			for(int i=1;i<=n;i++) printf("%d ",ans[i]);
			puts(""); return 0;
		}
	}
	puts("-1");
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	ll n;cin>>n;n--;
	string s;
	while(n>=0){
		s+='a'+n%26;
		n=n/26-1;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
}

Measured memory_bytes: 3612
#include<iostream>
#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 <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define ll  long long 
const ll INF=1LL<<60;
const ll mod=1000000007;
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
vector<vector<bool>>d(10001,vector<bool>(10010));
vector<pair<ll,ll>>s[100001];
ll dis[100001];
int main(){
  ll a;cin>>a;
  vector<ll>b(a),c(a),sum(a+1,0);
  rep(i,a)cin>>b[i];
  for(ll i=a-1;i>=0;i--){
    sum[i]+=b[i]+sum[i+1];
    sum[i]%=mod;
  }
  ll kotae=0;
  rep(i,a-1){
    kotae+=b[i]*sum[i+1];
    kotae%=mod;
  }
  cout<<kotae;
}


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

int main() {
  int n, i;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  while (true) {
    bool flag = false;
    for (i = 0; i < n; i++) {
      if (a[i] % 2 == 1) {
        flag = true;
        break;
      }
      a[i] /= 2;
    }
    if (flag) {
      break;
    }
    count++;
  }
  cout << count << endl;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int N;
vector<ll> X;
vector<ll> X_sorted;

int main(void) {
    cin >> N;

    rep(i, N) {
        ll a;
        cin >> a;
        X.push_back(a);
        X_sorted.push_back(a);
    }

    sort(ALLOF(X_sorted));

    REP(i, 0, N) {
        ll ans = 0;
        ll target = X[i]; // 1 origin
        // targetを見つける
        int ii = distance(X_sorted.begin(), lower_bound(ALLOF(X_sorted), target));

        if (ii < N / 2) {
            ans = X_sorted[N / 2];
        }
        else {
            ans = X_sorted[N / 2 - 1];
        }
        cout << ans << endl;
    }

    return 0;
}

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

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

Measured memory_bytes: 3616
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <time.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep_1(i,n) for(ll i=1;i<(ll)n;i++)
#define rep_3(j,m) for(ll j=3;j<(ll)m;j++)
using namespace std;

void chmin(ll a, ll b) {
    if (a > b) a = b;

}

int main() {
    ll N;
    cin >> N;
    vector <ll> A(N+1, 0);
    vector<ll> dp(N+1, 0);
    rep_1(i, N+1) cin >> A[i];
    dp[2] = abs(A[2] - A[1]);
    rep_3(j, N+1) {
        dp[j] = min(dp[j-2]+abs(A[j] - A[j - 2]),dp[j-1]+ abs(A[j] - A[j - 1]));
    }
    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*

fun main(args:Array<String>){
    val (a,b) = readLine()!!.split(" ").map{it.toInt()}
    val ans = Array(100){CharArray(100)}
    for(i in 0 until 100){
        for(j in 0 until 100){
            ans[i][j] = if(i < 50) '.' else '#'
        }
    }
    var white = 1
    var black = 1
    for(i in 0 until 50 step 2){
        for(j in 0 until 100 step 2){
            if(black < b){
                ans[i][j] = '#'
                black++
            }
        }
    }
    for(i in 99 downTo 50 step 2){
        for(j in 0 until 100 step 2){
            if(white < a){
                ans[i][j] = '.'
                white++
            }
        }
    }
    println("100 100")
    for(i in 0 until 100){
        for(j in 0 until 100){
            print(ans[i][j])
        }
        println()
    }
}

Measured memory_bytes: 40632
import sys
readline = sys.stdin.readline

def main():
    N, M, X = map(int, readline().rstrip().split())
    C, A = [], []
    for _ in range(N):
        c, *a = map(int, readline().rstrip().split())
        C.append(c)
        A.append(a)
    res = 10 ** 10
    for i in range(2**N):
        b = bin(i)[2:].zfill(N)
        buy_idx = [i for i, e in enumerate(b) if e == '1']
        flg = True
        for alg in range(M):
            if sum([A[j][alg] for j in buy_idx]) < X:
                flg = False
                break
        if flg:
            res = min(res, sum([C[j] for j in buy_idx]))

    if res == 10 ** 10:
        print(-1)
    else:
        print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9264
/* ex4-1
   kas056*/

#include <stdio.h>
#include <stdlib.h>

#define SIZE 15

typedef struct{
    int size;//格納最大数
    int count;//現在のデータ数
    char data[SIZE];//データ配列
    char *top;//topのポインタ
    char *bottom;//一番下のポインタ
}stack;

void initialize(stack *stk){
    stk -> count = 0;
    stk -> size = SIZE;
    stk -> top = &(stk->data[SIZE]);//配列の最終要素の一つ手前
    stk -> bottom = &(stk->data[SIZE]);//初期配列の要素の一つ手前...(*)
}

void push(stack *stk, char s){
    if(stk->count >= stk -> size){//格納最大数を超えたらエラー
        fprintf(stderr, "Error: Stack overflow. (s=%c)\n", s);
    }
    else{
        stk -> top--;//一つ上にあげる(=一つ手前に移動)
        *(stk->top) = s;
        stk->count++;
    }
}

void pop(stack *stk){
    //popが指示されたとき、
    if(stk->count > 0){//要素があれば取り出すようにする。
        stk->top++;//一つ下に移動(=一つ後に移動)
        stk->count--;
    }
}

void print_stack(stack *stk){
    char *c;
    int i;
    c = stk->bottom-1;//配列の一番下のポインタを指定する。
    
    for(i = stk->count-1; i>-1; i--){//スタック内の文字数分操作
        printf("%c", *c--);//出力したら一つ上にあげる。
    }
}


stack stk;
int main(void){
    char sentence[SIZE];
    int i;

    initialize(&stk);

    scanf("%s", sentence);

    for(i=0; i<SIZE; i++){
        if(sentence[i] == '0' || sentence[i] == '1'){
            push(&stk, sentence[i]);//B以外はpush
        }
        else if(sentence[i] == 'B'){
            pop(&stk);//Bがでたらpop
        }
        else{
            continue;
        }
    }

    print_stack(&stk);

    return 0;
    

}

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

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0) break;

    int count = 0;
    for (int b = 2; 2 * b - 1 <= n; b++) {
      int b2 = b * (b + 1) / 2;
      for (int a = 1; a < b; a++) {
	int a2 = a * (a - 1) / 2;
	if (b2 - a2 == n) count++;
      }
    }

    cout << count << endl;
  }

  return 0;
}

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

using namespace std;

//#define FILE_IO

typedef long long LL;
typedef pair<LL, LL> pll;

int N, v[1000005];
LL c[5], s[1000005];

vector<pll> cut(int st, int dr)
{
    vector<pll> ss;
    for(int i = st; i < dr; i++)
        ss.push_back({s[i] - s[st - 1], s[dr] - s[i]});
    sort(ss.begin(), ss.end(),
         [](pll a, pll b) { return abs(a.first - a.second) < abs(b.first - b.second); });

    if(ss.size() > 5)   ss.resize(5);
    return ss;
}

LL getcost()
{
    LL mx = max({c[1], c[2], c[3], c[4]});
    LL mn = min({c[1], c[2], c[3], c[4]});
    return (mx - mn);
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d", &v[i]);
        s[i] = s[i - 1] + v[i];
    }

    LL ans = 1LL << 60;
    int pst = 1, pdr = 1;
    LL bst = 1LL << 60;
    for(int i = 3; i < N; i++)
    {
        LL cst = abs(s[N] - s[i] - s[i] + s[2]);
        if(cst < bst)
        {
            bst = cst;
            pdr = i;
        }
    }

    c[1] = v[1];
    c[2] = v[2];
    c[3] = s[pdr] - s[2];
    c[4] = s[N] - s[pdr];
    ans = getcost();
    for(int i = 3; i <= N - 2; i++)
    {
        c[2] += v[i];
        c[3] -= v[i];
        while(pst < i - 1)
        {
            if(abs(c[1] - c[2]) < abs(c[1] + v[pst + 1] - c[2] + v[pst + 1]))   break;
            pst++;
            c[1] += v[pst];
            c[2] -= v[pst];
        }

        while(pdr < N - 1)
        {
            if(abs(c[3] - c[4]) < abs(c[3] + v[pdr + 1] - c[4] + v[pdr + 1]))   break;
            pdr++;
            c[3] += v[pdr];
            c[4] -= v[pdr];
        }

        LL sol = getcost();
        ans = min(ans, sol);
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 5888
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

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

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 n;
    cin >> n;

    s64 ans = n * (n - 1) / 2;

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(snip_i, n) cin >> a.at(snip_i);
  sort(a.begin(), a.end());
  vector<ll> sums(n+1, 0);
  rep(i, n){
    sums.at(i+1) = sums.at(i) + a.at(i);
  }
  int ans = 1;
  rrep(i, n-1){
    ll ns = sums.at(i+1), na = a.at(i+1);
    if(ns *2 < na) break;
    ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define puu pair<ull,ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vll vector<ll>
#define Vull vector<ull>
#define nl cout<<endl
#define sp cout<<" "
#define MOD 1000000007
#define all(x) x.begin(),x.end()

int main() 
{
	 // #ifndef ONLINE_JUDGE
  //       freopen("input.txt", "r", stdin);
  //       freopen("output.txt", "w", stdout);
  //   #endif
  //   fastio();
    ll n;
    cin>>n;
    vector<ll> v(n);
    loop(i,0,n)
    	cin>>v[i];
    vector<ll> dp(n);
    dp[1] = abs(v[1]-v[0]);
    loop(i,2,n)
    {
    	dp[i] = min(dp[i-2] + abs(v[i] - v[i-2]),dp[i-1] + abs(v[i] - v[i-1]));
    }

    cout<<dp[n-1];


}

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

int gcd(int a,int b) {
    if(a<b) {
        int tmp1 = a;
        int tmp2 = b;
        a = tmp2;
        b = tmp1;
    }     
    
    
    if(a%b == 0) {
        return b;
    } else {
        return gcd(b,(a%b));
    }
}
 
int main(){
    int K;
    cin >> K;

    long int sum = 0;

    rep(i,K) {
        rep(j,K) {
            rep(k,K) {
                sum += gcd(i,gcd(j,k));
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

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

	if (abs(a - x) < abs(b - x))cout << 'A' << endl;
	else cout << 'B' << endl;


}


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

using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> p;

  for(int i = 0; i < n; i++){
    int tmp;
    cin >>tmp;
    p.push_back(tmp);
  }

  int cnt = 0;
  int min = *max_element(p.begin(), p.end()) + 1;
  for(int i = 0; i < n; i++){
    if(p[i] < min) {
      min = p[i];
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 4320
#include <bits/stdc++.h>
#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 k, a, b;
    cin >> k;
    cin >> a >> b;
    rep(i, b-a+1){
        if((a+i)%k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		while (n--)
		{
			int m, e, j;
			scanf("%d%d%d", &m, &e, &j);
			int ave = (m + e + j) / 3;
			int r = 0;
			if (m == 100 || e == 100 || j == 100
				|| (m + e) / 2 >= 90
				|| ave >= 80)
				r = 2;
			else if (ave >= 70
				|| ave >= 50 && (m >= 80 || e >= 80))
				r = 1;

			printf("%c\n", r == 0 ? 'C' : (r == 1 ? 'B' : 'A'));
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}






void test_case() {

    ld n;
    cin>>n;


    ld a = n/3;
    ld b = n/3;

    ld c = n - a - b;


    cout<<a*b*c<<endl;


  

    


}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
inline long long ksm(long long b,long long n,long long mod)
{
	long long ans=1;
	while(n)
	{
		if(n%2!=0)
			ans=ans*b%mod;
		b=b*b%mod;
		n>>=1;
	}
	return ans;
}
long long c[3005][3005];
long long g[3005][3005];
int main()
{
	long long n,mod,k,kind,x,cnt,y,i,j,ans=0;
	cin>>n>>mod;
	for(i=1;i<=n;i++)
	{
		c[i][0]=1;
		c[i][i]=1;
		for(j=1;j<i;j++)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	for(i=0;i<=n;i++)
	{
		g[i][0]=1;
		for(j=1;j<=i;j++)
			g[i][j]=(g[i-1][j-1]+g[i-1][j]*(j+1)%mod)%mod;
	}
	for(i=0;i<=n;i++)
	{
		k=c[n][i];
		if(i&1)
			k=(mod-k)%mod;
		kind=ksm(2,n-i,mod);
		x=ksm(2,n-i,mod-1);
		x=ksm(2,x,mod);
		cnt=0,y=1;
		for(j=0;j<=i;j++)
		{
			cnt=(cnt+(g[i][j]*y%mod))%mod;
			y=kind*y%mod;
		}
		ans=(ans+k*cnt%mod*x%mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 95900
ds = [int(input()) for _ in range(5)]
ls = 10

for i in range(5):
    m = ds[i] % 10

    if ls > m > 0:
        ls = m

    if m > 0:
        ds[i] += 10 - m

res = sum(ds) - (10 - ls)
print(res)

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int a, b, c, d, p;
int pA, pB;
int main(){
    cin >> a >> b >> c >> d >> p;
pA = a * p;
if (p <= c) {
  pB = b;
}else {
pB = b + (p - c) * d;
}
cout << min(pA, pB) << endl;
return 0;
}

Measured memory_bytes: 3100
#include <stdio.h>
int main(){
    int s, m, h, x;
    scanf("%d", &x);
    h = x / 3600;
    m = (x - 3600 * h) / 60;
    s = x - (3600 * h + 60 * m);
    printf("%d:%d:%d\n", h, m, s);
}

Measured memory_bytes: 1852
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int k, n;
  cin >> k >> n;
  int bf = -1;
  vector<int> d(n);
  int fr = -1;
  rep(i, n){
    int a;
    cin >> a;
    if(i != 0){
      d.at(i-1) = a - bf;
    }else{
      fr = a;
    }
    bf = a;
  }
  d.at(n-1) = k - bf + fr;
  int mx = 0;
  rep(i, n){
    // cerr << d.at(i) << endl;
    mx = max(mx, d.at(i));
  }
  cout << k - mx << endl;
  return 0;
}

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

int main(){
    int a, b;
    
    cin >> a >> b;
    
    if(a < b){
      cout << "a < b" << endl;
    }
    else if(a > b){
      cout << "a > b" << endl;
    }
    else if(a == b){
      cout << "a == b" << endl;
    }
    else{
      cout << "!?" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        if (a == b) {
            System.out.println(c);
        } else if(b == c) {
            System.out.println(a);
        } else {
            System.out.println(b);
        }
    }
}



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

#define int long long int 

int32_t main()
{
    int n;
    cin>>n;
    set<int> s;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        s.insert(x);
    }
    cout<<s.size()<<endl;
}

Measured memory_bytes: 3656
#include <stdio.h>

int main(void) {
	int n, m, k, a, ans = 0;
	int A[30]={ 0 };

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

		scanf("%d ", &k);
		for (int j = 0; j < k; ++j) {
			scanf("%d", &a);
			A[a-1] += 1;
		}

	}

	for (int i = 0; i < m; ++i) {
		if (A[i] == n) {
			++ans;
		}
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    string s;
    cin >> s;
    int flag = 0;
    for (ll i=0;i<s.length();i++){
        if(i%2 == 0){
            if(s[i] == 'L'){
                flag = 1;
            }
        }else{
            if(s[i] == 'R'){
                flag = 1;
            }
        }
    }
    if(flag){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int k,q;
ll d[5005];
ll times[5005];
int main(){
	cin>>k>>q;
	
	for (int x=0;x<k;x++) cin>>d[x];
	
	
	int len,seed,mod;
	while (q--){
		cin>>len>>seed>>mod;
		
		len--;
		for (int x=0;x<k;x++) times[x]=len/k+(len%k>x);
		
		ll total=seed%mod;
		ll ans=0;
		
		for (int x=0;x<k;x++){
			total+=times[x]*(d[x]%mod);
			if (d[x]%mod) ans+=times[x];
		}
		
		ans-=total/mod;
		cout<<ans<<endl;
	}
}
/*
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int k,q;
ll d[5005];
ll times[5005];
int main(){
	cin>>k>>q;
	
	for (int x=0;x<k;x++) cin>>d[x];
	
	
	int len,seed,mod;
	while (q--){
		cin>>len>>seed>>mod;
		
		len--;
		for (int x=0;x<k;x++) times[x]=len/k+(len%k>x);
		
		ll total=seed%mod;
		ll ans=0;
		
		for (int x=0;x<k;x++){
			total+=times[x]*(d[x]%mod);
			if (d[x]%mod) ans+=times[x];
		}
		
		ans-=total/mod;
		cout<<ans<<endl;
	}
}
*/

Measured memory_bytes: 384
#include <stdio.h>

int main(void){

	int n;
	long x[100000];
	int i;
	long max, min, sum;

	scanf("%d", &n);
	scanf("%ld",&x[0]);
	max = x[0];
	min = x[0];
	sum = x[0];

	for (i = 1; i < n; i++){

		scanf("%ld", &x[i]);

		if (max < x[i]){
			max = x[i];
		}

		if (x[i] < min){
			min = x[i];
		}

		sum += x[i];
	}

	printf("%ld %ld %ld\n", min, max, sum);

	return 0;
}

Measured memory_bytes: 684
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/


int main(){
    ll n,t;
    cin>>n>>t;
    ll sum=0;
    vec(a,n);
    rep(i,n){
        cin>>a[i];
    }
    repf(i,1,n){
        if(a[i-1]+t>a[i]){
            sum+=(a[i]-a[i-1]);
        }else{
            sum+=t;
        }
    }
    sum+=t;
    op(sum);
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define N 100

void bubbleSort(int*, int);

int main(void){

	int A[N],n;
	int i=0;

	scanf("%d",&n);

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

	bubbleSort(A,n);

	return 0;
}

void bubbleSort(int *A, int n){

	int i,j,swap,count=0;

	for(i = 0; i < n-1; i++){
		for(j = n-1; j >= i; j-- ){
			if(A[j] < A[j-1]){
				swap = A[j];
				A[j] = A[j-1];
				A[j-1] = swap;
				count++;
			}
		}
	}

	for (i = 0; i < n-1; i++){
		printf("%d ",A[i]);
	}
	printf("%d\n",A[n-1]);
	printf("%d\n",count);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/




int main(void) {
  ll i, j, k;
  
  double L;
  cin >> L;
  
  double x=L/3;
  
  printf("%.10f\n", x*x*x);
  
}




Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

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

struct Mod {
    static ll gcd(ll x, ll y, ll* out_cx, ll* out_cy) {
        if (x < 0) {
            ll d = gcd(-x, y, out_cx, out_cy);
            if (out_cx) {
                *out_cx *= -1;
            }
            return d;
        }
        if (y < 0) {
            ll d = gcd(x, -y, out_cx, out_cy);
            if (out_cy) {
                *out_cy *= -1;
            }
            return d;
        }
        if (x > y) {
            return gcd(y, x, out_cy, out_cx);
        }
        if (x == 0) {
            if (out_cx && out_cy) {
                *out_cx = 0;
                *out_cy = 1;
            }
            return y;
        }
        ll q = y / x;
        ll r = y % x;
        ll d = gcd(r, x, out_cy, out_cx);
        if (out_cx) {
            *out_cx -= q * *out_cy;
        }
        return d;
    }
    static ll BASE;
    ll value = 0;
    static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
    Mod()
    : value(0) {}
    Mod(ll value)
    : value(residue(value)) {}
    Mod operator+(const Mod& rhs) const { return Mod(value + rhs.value); }
    void operator+=(const Mod& rhs) { *this = *this + rhs; }
    Mod operator-(const Mod& rhs) const { return Mod(value - rhs.value); }
    void operator-=(const Mod& rhs) { *this = *this - rhs; }
    Mod operator*(const Mod& rhs) const { return Mod(value * rhs.value); }
    void operator*=(const Mod& rhs) { *this = *this * rhs; }
    Mod operator/(const Mod& rhs) const { return *this * rhs.inv(); }
    void operator/=(const Mod& rhs) { *this = *this / rhs; }
    Mod inv() const {
        if (value == 0) {
            assert(false);
            throw "[Mod::inv] div by zero";
        }
        ll ans, sub;
        ll d = Mod::gcd(value, BASE, &ans, &sub);
        if (d != 1) {
            assert(false);
            throw "[Mod::inv] not invertible";
        }
        return ans;
    }
};
ll Mod::BASE = 1000000007;

int main() {
    ll N, M;
    cin >> N >> M;
    Mod::BASE = M;
    vector<ll> Ais(N);
    rep(i,0,N) {
        cin >> Ais[i];
    }
    unordered_map<ll, ll> sums;
    Mod sum = 0;
    sums[sum.value]++;
    rep(i,0,N) {
        sum += Ais[i];
        sums[sum.value]++;
    }
    ll ans = 0;
    for (auto& kv : sums) {
        ll n = kv.second;
        ans += n*(n-1)/2;
    }
    cout << ans << endl;
}



Measured memory_bytes: 4768
local x = io.read("*l"):match("(%d+)")
local arr = {}
local a,b
local result = 0
for i = 1,tonumber(x) do
  arr[i] = 1
end
b = 0
for _ in io.read("*l"):gmatch("%d+") do
  b = b + 1
  a = tonumber(_)
  arr[a] = b
end
local xx = tonumber(x)
for i = 1,xx do
  io.write(arr[i])
  if i == xx then
    break
  end
  io.write(" ")
end

Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
#define Endl '\n'
typedef long long int lli;
void solve();
int main(int argc, char const *argv[]){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
    solve();
}
void solve(){
  int N;
  cin>>N;
  set<string> s;
  for(int i=0;i<N;i++){
    string si;
    cin>>si;
    s.insert(si);
  }
  cout<<s.size()<<Endl;
}


Measured memory_bytes: 19248
n = int(input())  # 数値入力
li = list()

for i in range(n):
    s, p = input().split()
    li.append([s, int(p), i+1])

li.sort()
lastcity = li[0][0]
newli = list()

for i in range(n):
    if lastcity == li[i][0]:
        newli.append([li[i][1], li[i][2]])
        lastcity = li[i][0]
    else:
        newli = newli[::-1]
        for tmp in newli:
            print(tmp[1])
        newli = list()
        newli.append([li[i][1], li[i][2]])
        lastcity = li[i][0]

newli = newli[::-1]
for tmp in newli:
    print(tmp[1])


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
int main()
{
	char c;
	c = getchar();
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
		printf("vowel\n");
	else 
		printf("consonant\n");
	system("pause");
}


Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a, b, k;
vector<ll> yaku;

ll gcd(ll x, ll y)
{
	if (y == 0) return x;
	return gcd(y, x % y);
}

int main()
{
	cin >> a >> b >> k;
	ll c = gcd(a, b);
	for (int i = c; i >= 1; i--)
	{
		if (c % i) continue;
		yaku.push_back(i);
	}
	cout << yaku[k - 1] << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
import Data.Array.IArray
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
-- end of templete


main = do
    [n,y] <- getInts
    let y' = div y 1000
    let c = y' - n
    let r = [(x, y, z) | x <- [0..c`div`9], let (y,r) = divMod (c-9*x) 4, let z = n - x - y, r==0, y<=n, z>=0, z<=n]
    putStrLn $ if null r then "-1 -1 -1" else let (x,y,z) = head r in sjoin [x,y,z]

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef long long lint;
const int offset = 2500;

int nxt[17][100005];
int n, a[100005], l;

int main(){
	cin >> n;
	for(int i=0; i<n; i++){
		scanf("%d",&a[i]);
	}
	cin >> l;
	int p = 0;
	for(int i=0; i<n; i++){
		while(p+1 < n && a[p+1] - a[i] <= l) p++;
		nxt[0][i] = p;
	}
	for(int i=1; i<17; i++){
		for(int j=0; j<n; j++){
			nxt[i][j] = nxt[i-1][nxt[i-1][j]];
		}
	}
	int q;
	cin >> q;
	while(q--){
		int s, e;
		scanf("%d %d",&s,&e);
		s--, e--;
		if(s > e) swap(s, e);
		int ret = 0;
		for(int i=16; i>=0; i--){
			if(nxt[i][s] < e){
				s = nxt[i][s];
				ret += (1<<i);
			}
		}
		if(s < e) s = nxt[0][s], ret++;
		printf("%d\n", ret);
	}
}


Measured memory_bytes: 7808
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>

using namespace std;

int main(){
	
	int n,a,b,c,x;
	
	while(cin>>n>>a>>b>>c>>x, n){
		
		vector<int> y(n);
		
		for(int i=0; i<n; ++i){
			cin>>y[i];
		}
		
		int res = -1;
		int cnt = 0;
		vector<int>::iterator it;
		
		for(int t=0; t<=10000; ++t){
			
			if(y[cnt] == x){
				cnt++;
			}
			
			if(cnt==n){
				res = t;
				break;
			}
			
			x = (a*x+b)%c;
		}
		
		cout << res << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod =1e9+7;
const int N = (int)2e5 + 5;


void solve(){
	int x;
	cin>>x;
	int r=x/500;
	int n=x-r*500;
	int z=n/5;
	cout<<r*1000+z*5;	



}
int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const ll MAXN = 1e5+5;
 
ll n, a[MAXN], val[MAXN];
vector<ll> g[MAXN];
 
void dfs(ll v, ll f = -1) {
    ll ct = 0;
    for (ll u : g[v]) {
        if (u == f)
            continue;
        ct++;
        dfs(u, v);
    }
 
    if (ct == 0) {
        val[v] = a[v];
        return;
    }
 
    vector<ll> w;
    for (ll u : g[v]) {
        if (u == f)
            continue;
        w.push_back(val[u]);
    }
    sort(w.begin(), w.end());
    ll sum = 0, sum1 = 0;
    for (ll i = 0; i < w.size(); ++i) {
        sum += w[i];
        if (i == w.size()-1) {
            sum1 = sum;
            sum1 -= w[i];
        }
    }
 
    ll m = sum - a[v];
    if (m < 0 || m > sum1) {
        cout << "NO\n";
        exit(0);
    } if (a[v] - m < 0) {
        cout << "NO\n";
        exit(0);
    }
 
    val[v] = a[v] - m;
}
 
int main() {
    cin >> n;
    for (ll i = 0; i < n; ++i)
        cin >> a[i];
 
    for (ll i = 0; i < n-1; ++i) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
 
    if (n == 2) {
        if (a[0] == a[1]) {
            cout << "YES\n";
        } else
            cout << "NO\n";
        return 0;
    }
 
    for (ll i = 0; i < n; ++i) {
        if (g[i].size() > 1) {
            dfs(i);
            if (val[i] == 0) {
                cout << "YES\n";
            } else
                cout << "NO\n";
            return 0;
        }
    }
}

Measured memory_bytes: 16640
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

const int INF = 1 << 30;

struct pos {
    int h, w, d;
    pos(int h_, int w_, int d_):h(h_), w(w_), d(d_) {}
};

int dh[4] = {-1, 0, 1, 0}, dw[4] = {0, -1, 0, 1};
int H, W;

int bfs(const vector<string>& grid, int sh, int sw, int gh, int gw) {
    if (grid[sh][sw] == '#' || grid[gh][gw] == '#') {
        return 0;
    }
    queue<pos> que;
    que.push({sh, sw, 0});
    vector<vector<int>> dist(H, vector<int>(W, INF));
    dist[sh][sw] = 0;
    while (!que.empty()) {
        int now_h = que.front().h;
        int now_w = que.front().w;
        que.pop();
        rep(i, 0, 4) {
            int next_h = now_h + dh[i];
            int next_w = now_w + dw[i];
            if (next_h < H && next_h >= 0 && next_w < W && next_w >= 0 && grid[next_h][next_w] == '.' && dist[next_h][next_w] == INF) {
                dist[next_h][next_w] = dist[now_h][now_w] + 1;
                que.push({next_h, next_w, dist[now_h][now_w] + 1});
            }
        }
    }
    return dist[gh][gw];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    vector<string> grid(H);
    rep(i, 0, H) {
        cin >> grid[i];
    }
    int ans = 0;
    rep(sh, 0, H) rep(sw, 0, W) rep(gh, 0, H) rep(gw, 0, W) {
        ans = max(ans, bfs(grid, sh, sw, gh, gw));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){
  int b[100];
  int n;
  int score;
  scanf("%d\n",&n);
  for(int i=0; i<n; i++) {
    scanf("%d",&b[i]);
    if(b[i]>i+1) {
      printf("-1");
      return 0;
    }
  }
  for(int i=0; i<n;i++){
    for(int j=n-1; j>=0; j--){
      score = 1;
      if(b[j] > n) continue;
      for(int k=j-1; k>=0; k--){
        if(b[k]==200) score++;
      }
      if(score == b[j]) {
        printf("%d\n",b[j]);
        b[j] = 200;
        break;
      }
    }
  }     
  return 0;
}

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

using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
const int N=1000005,MOD=1e9+7,MAX=1e5;


int main()
{
      
        
           ll k;
           string str;
        
        cin>>str>>k;
         

         for(int i=0;i<min((ll)str.size(),k);i++){

             if(str[i]!='1')
              return cout<<str[i]<<endl,0;
         }

         cout<<'1'<<endl;

       
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  char a, b;
  cin >> a >> b;
  if (a == 'H') {
    if (b == 'H') {
      cout << 'H' << endl;
    } else {
      cout << 'D' << endl;
    }
  } else {
    if (b == 'H') {
      cout << 'D' << endl;
    } else {
      cout << 'H' << endl;
    }
  }
}

Measured memory_bytes: 3632
N = int(input())
S = str(N)
L = list(S)

for x in range(len(L)):
    L[x] = int(L[x])

for x in range(1, len(L)):
    if L[x] != 9:
        L[x-1] -= 1

        for y in range(x, len(L)):
            L[y] = 9

res = 0

for x in L:
    res += x

print(res)


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

typedef long long ll;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void run() {
  int n;
  cin >> n;
  vector<ll> ar(n);
  for(auto &x : ar) cin >> x;
  ll res = 0, m = 1e9 + 7;
  auto mul = [&](ll a, ll b) {
    return (a * b) % m;
  };
  for(ll i = 0; i < 60; i++) {
    ll bit = (1LL << i);
    ll a = 0, b = 0;
    for(auto &x : ar) {
      if (x & bit) a++;
      else b++;
    }
    ll t = mul(a, b);
    for(int j = 0; j < i; j++) t = mul(t, 2);
    res += t;
    res %= m;
  }
  cout << res;
}

signed main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
 // freopen("divljak.in", "r", stdin);
 // freopen("divljak.out", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(2);
  run();
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  while (!s.empty() && s.back() == 'W')
    s.pop_back();
  reverse(s.begin(), s.end());
  int n = s.length();
  long long ans = 0;
  int p = 0;
  for (int i = 0; i < n; ++i)
    if (s[i] == 'W')
      ans += i - p, ++p;
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define int long long
using namespace std;
int x,q,n,f[100005],a[100005],ans[100005],m;
void doit(int x,int v)
{
	if(!x) return;int t=upper_bound(f+1,f+m+1,x)-f-1;
	if(t==0) ans[1]+=v, ans[x+1]-=v;else a[t]+=(x/f[t])*v,doit(x%f[t],v);
}
main()
{
	scanf("%lld%lld",&n,&q);f[++m]=n;
	for(int i=1;i<=q;++i) {scanf("%lld",&x);while(m&&f[m]>=x) m--;f[++m]=x;}
	a[m]=1;for(int i=m;i>=2;--i) a[i-1]+=a[i]*(f[i]/f[i-1]),doit(f[i]%f[i-1],a[i]);
	ans[1]+=a[1];ans[f[1]+1]-=a[1];for(int i=2;i<=n;++i) ans[i]+=ans[i-1];
	for(int i=1;i<=n;++i) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 4096
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	int x;cin>>x;cout<<(x<30?"No\n":"Yes\n");
}


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

Measured memory_bytes: 256