akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
  int a,b;
  cin>>a>>b;
  
  if((a==1||a==3||a==5||a==7||a==8||a==10||a==12)&&(b==1||b==3||b==5||b==7||b==8||b==10||b==12)){
      cout<<"Yes"<<endl;
  }
  
  else if((a==4||a==6||a==9||a==11)&&(b==4||b==6||b==9||b==11)){
      cout<<"Yes"<<endl;
  }
  
  else if(a==2&&b==2){
      cout<<"Yes"<<endl;
  }
  
  else{
      cout<<"No"<<endl;
  }
    
}


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

using namespace std;

#define ll long long
#define endl "\n"

void solve() {
  ll n;
  cin >> n;
  vector<string> v;
  string x;
  for (ll i = 0; i < n; ++i) {
    cin >> x;
    sort(x.begin(), x.end());
    v.emplace_back(x);
  }
  sort(v.begin(), v.end());
  vector<ll> aux;
  ll len = 1;
  for (ll i = 0; i < n - 1; ++i) {
    if (v[i] == v[i + 1]) {
      ++len;
    } else {
      aux.emplace_back(len);
      len = 1;
    }
  }
  aux.emplace_back(len);
  ll ans = 0;
  for (ll x : aux) {
    ans += (1ll * (x * x - x)) >> 1;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 8236
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <iomanip>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

ll BASE_NUM = 1000000007;

long long extGCD(long long a, long long b, long long &x, long long &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

ll reverse(ll n,ll modulo){
    ll x,y;
    extGCD(n, modulo, x, y);
    return (x + ((abs(x / modulo) + 1) * modulo)) % modulo;
}

int main()
{
    // 整数の入力
    ll N;
    vector<ll> X;
    cin >> N;
    ll BASE = 1;
    for(int i = 1;i<=N-1;i++){
        BASE = BASE * i % BASE_NUM;
    }

    for(int i = 0;i<N;i++){
        ll x;
        cin >> x;
        X.push_back(x);
    }
    ll mean = 0;
    ll times = 0;

    for(int i = 0; i< N -1;i++){
        ll current_time = BASE * reverse(i+1,BASE_NUM) % BASE_NUM;
        times = (times + current_time) % BASE_NUM;
        ll current_mean = times * (X[i+1] - X[i]) % BASE_NUM;
        mean = (mean + current_mean) % BASE_NUM;
    }
    cout << mean << endl;
    return 0;
}

Measured memory_bytes: 1400
N, M = map(int, input().split())
S = []
for i in range(M):
    S.append(list(map(int, input().split()))[1:])
P = list(map(int, input().split()))
cnt = 0
cnt_all = True
ans = 0
for i in range(2 ** N):
    for j in range(M):
        for k in range(len(S[j])):
            cnt += (i >> (S[j][k] - 1)) & 1
        if cnt % 2 != P[j]:
            cnt_all = False
        cnt = 0
    if cnt_all:
        ans += 1
    cnt_all = True
print(ans)


Measured memory_bytes: 41328
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define all(c) begin(c),end(c)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//最大公約数
ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}
//最小公倍数
ll lcm(ll x, ll y) {
  return x/gcd(x, y)*y;
}
//素因数分解
vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}
 
 
 ll mod=100000007;
 
int main() {
  int k;
  ll ans=1;
  cin>>k;
  if(k%2==0||k%5==0){
    cout<<-1;
    return 0;
  }
  ll num=7%k;

  while(num){
    num=(num*10+7)%k;
    ans++;
  }

  cout<<ans;
 
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;
typedef long long ll;
typedef pair<int,int> pii;

int w, h;
inline bool get(ll S, int y, int x) {
  return S>>(y*w+x)&1;
}
inline ll bit(int y, int x) {
  return 1LL<<(y*w+x);
}
inline bool ok(ll S, int y, int x) {
  if (y<0||y>=h||x<0||x>=w) return 0;
  if (get(S,y,x)) return 0;
  return 1;
}
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

bool visited[7][7];
int sy,sx;
map<ll, int> mp[7][7];
bool dfs(ll S, int y, int x, int num) {
//  if (num < 30) {
  if (y) { 
    if (mp[y][x].count(S)) return 0;
    mp[y][x][S] = 1;
  }
//  }
  // cout << y << "," << x << "," << num << endl;
  // REP(i,h) {
  //   REP(j,w) cout << get(S,i,j);
  //   cout << endl;
  // }
  if (num == 0) {
    return abs(y-sy)+abs(x-sx) == 1;
  }
  // BFSして領域が2つあったらだめ
  {
    REP(i,h)REP(j,w)visited[i][j]=0;
    REP(i,h)REP(j,w) {
      if (get(S,i,j)) continue;
      queue<pii>Q;
      Q.push(pii(i,j));
      visited[i][j] = 1;
      int cnt = 0;
      while(!Q.empty()) {
        pii p = Q.front(); Q.pop();
        ++cnt;
        REP(k,4) {
          int ii=p.first+dy[k];
          int jj=p.second+dx[k];
          if (!ok(S,ii,jj)) continue;
          if (visited[ii][jj]) continue;
          visited[ii][jj] = 1;
          Q.push(pii(ii,jj));
        }
      }
      if (cnt != num) return 0;
      goto next;
    }
  next:;
  }
  {
    // 今の場所と最初の場所以外で凸の部分があったらだめ
    int cnt = 0;
    REP(i,h)REP(j,w) {
      if (get(S,i,j)) continue;
      int c = 0;
      REP(k,4) {
        int ii=i+dy[k];
        int jj=j+dx[k];
        if (!ok(S,ii,jj)) {
          if (ii!=y||jj!=x) {
            if (ii!=sy||jj!=sx) {
              ++c;
            }
          }
        }
      }
      if (c >= 3) {
        ++cnt;
      }
    }
    if (cnt >= 1) return 0;
  }
  REP(k,4) {
    int yy=y+dy[k];
    int xx=x+dx[k];
    if (!ok(S,yy,xx)) continue;
    if (dfs(S|bit(yy,xx),yy,xx,num-1)) return 1;
  }
  return 0;
}

int main() {
  while(cin>>w>>h,w||h) {
    ll S = 0;
    int num = 0;
    REP(i,h) REP(j,w) {
      int a; cin >> a;
      if (a) S |= bit(i,j);
      else {
        sy=i,sx=j;
        ++num;
      }
    }
    if (num <= 3) {               // 空きマスが3以下
      puts("No");
      continue;
    }
    S |= bit(sy,sx); --num;
    REP(i,h)REP(j,w) mp[i][j].clear();
    cout << (dfs(S,sy,sx,num)?"Yes":"No") << endl;
  }
}

Measured memory_bytes: 32268
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    for(int i = 0; i < n-1; i++) {
        if(s[i] == s[i+1]) {
            continue;
        } else {
            ans++;
        }
    }
    cout << ans+1;
    return 0;
}

Measured memory_bytes: 512
// HとWが少ないので全探索ですね
#include <bits/stdc++.h>
using namespace std;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    char mass[H][W + 10];
    for (int i = 0; i < H; ++i) {
        cin >> mass[i];
    }
    int ans(0);
    for (int row = 0; row < (1 << H); ++row) {
        for (int col = 0; col < (1 << W); ++col) {
            int res(0);
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    if ((row >> i) & 1 ^ 1 && (col >> j) & 1 ^ 1 && mass[i][j] == '#') {
                        ++res;
                    }
                }
            }
            if (res == K) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
#include<string>
#define PP std::pair<std::string,int>
std::string S;
std::vector<PP> A;
int K;
std::vector<int> alpha[26];
int main() {
	std::cin >> S >> K;
	for (int i = 0; i < S.size(); i++) {
		alpha[S[i] - 'a'].emplace_back(i);
		char c[1] = { S[i] };
		A.emplace_back(PP{ std::string(c,1),i });
	}
	std::string ans = " ";
	std::sort(A.begin(), A.end());
	for (int i = 0; i < K; i++) {
		for (auto &u : A) {
			if (u.first == ans) {
				if (u.second != S.size() - 1) {
					u.second++;
					u.first += S[u.second];
				}
			}
		}
		std::sort(A.begin(), A.end());
		for (auto u : A) {
			if (u.first > ans) {
				ans = u.first;
				break;
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

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

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

  vector<int> T(N);
  int A;
  rep(i, N) {
    cin >> A;
    T[A - 1] = i + 1;
  }
  rep(i, N) cout << T[i] << " ";
  return 0;
}

Measured memory_bytes: 3688
N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ans = -float('inf')
d = len(V)
for b in range(2 ** d):
    tmp = 0
    for j in range(d):
        if ((b >> j) & 1):
            tmp += V[j] - C[j]
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 42220
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	int x;
	cin >> x;

	string ans = "No";
	if (x >= 30) {
		ans = "Yes";
	}

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


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
#define eprintf(...) fprintf(stderr,__VA_ARGS__)

const int N=int(1e5)+5;
const ll inf=ll(1e18)+7;

int n,k;
int a[N];
ll sum[N],pre[N];

int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+a[i];
		pre[i]=pre[i-1]+max(a[i],0);
	}
	ll ans=-inf;
	for(int i=0;i<=n-k;i++){
		ans=max(ans,max(0LL,sum[i+k]-sum[i])+pre[i]+(pre[n]-pre[i+k]));
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define maxIndex(v) max_element(v.begin(), v.end()) - v.begin()
#define maxElement(v) *max_element(v.begin(), v.end())
#define minIndex(v) min_element(v.begin(), v.end()) - v.begin()
#define minElement(v) *min_element(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;

int main()
{
  ll N; cin >> N;
  vector<pair<ll, ll>> pf;
  ll ans = 1;
  rep(i, 2, N + 1) {
  	ll K = i; bool isPrime = true;
    rep(j, 0, pf.size()) {
    	while(K % pf[j].first == 0) {
        	pf[j].second++;
          	isPrime = false;
          	K /= pf[j].first;
        }
    }
    if (isPrime) {
    	pf.push_back(make_pair(i, 1));
    }
  }
  rep(i, 0, pf.size()) {
  	ans *= pf[i].second + 1;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import copy
N,M=map(int,raw_input().split())
v=[False for _ in range(N+1)]
v[0]=True
s=[map(int,raw_input().split()) for _ in range(M)]

def recursion(V,p):
    m=0
    for a,b in s:
        if p==a :
            if V[b]:
                continue
            else:
                tmp=copy.deepcopy(V)
                tmp[b]=True
                if all(tmp):
                    m+=1
                else:
                    m+=recursion(tmp,b)
        elif p==b :
            if V[a]:
                continue
            else:
                tmp=copy.deepcopy(V)
                tmp[a]=True
                if all(tmp):
                    m+=1
                else:
                    m+=recursion(tmp,a)
    return m

v[1]=True
print recursion(v,1)

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

using namespace std;

bool comp2(const pair<int, pair<int, int>> &a, const pair<int, pair<int, int>> &b){
  return a.second.second < b.second.second;
}

int main(void){
  int N, M;
  cin >> N >> M;
  vector<pair<int, pair<int, int>>> v(M);
  for(int i = 0; i < M; i++){
    int P, Y;
    cin >> P >> Y;
    v[i] = make_pair(P, make_pair(Y, i));
  }
  sort(v.begin(), v.end());
  int P = v[0].first;
  int c = 1;
  for(int i = 0; i < M; i++){
    //cout << v[i].first << " " << v[i].second.first << " " << v[i].second.second << endl;
    if(P != v[i].first){
      P = v[i].first;
      c = 1;
    }
    v[i].second.first = c++;
  }
  sort(v.begin(), v.end(), comp2);
  for(int i = 0; i < M; i++) printf("%06d%06d\n", v[i].first, v[i].second.first);
  return 0;
}


Measured memory_bytes: 2688
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[][] nums=new int[n][3];
        for(int i=0;i<n-1;i++){
            for(int j=0;j<3;j++){
                nums[i][j]=sc.nextInt();
            }
        }
        int time;
        for(int i=0;i<n;i++){
            time=0;
            for(int j=i;j<n-1;j++){
                while((time-nums[j][1])%nums[j][2]!=0||time<nums[j][1]){
                    time++;
                }
                time+=nums[j][0];
            }
            System.out.println(time);
        }
                
    }
}

Measured memory_bytes: 25304
A, B, C = map(int, input().split())
K = int(input())

while K != 0:
    if B <= A:
        B *= 2
    elif C <= B:
        C *= 2
    else:
        break
    K -= 1

if (A < B) and (B < C):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
 
int32_t main(){
    IOS;
    ll t;
    cin >> t;
    if(t>=30) cout <<"Yes\n";
    else cout <<"No\n";  
} 

Measured memory_bytes: 3664
S=list(input())
T=list(input())
b=0
c=len(T)


for i in range(0,len(S)-len(T)+1):
    for j in range(0,len(T)):
       
        if S[i+j]!=T[j]:
            b+=1
    c=min(c,b)
    b=0
    
print(c)

Measured memory_bytes: 9104
def main():
    N = int(input())
    A = list(map(int,input().split()))
    A_num = [0] * N
    for a in A:
        A_num[a-1] += 1

    A_product = [0] * N
    A_product_1 = [0] * N
    for i in range(N):
        a = A_num[i]
        A_product[i] = int(a * (a-1) / 2)
        if a == 0:
            A_product_1[i] = 0
        else:
            A_product_1[i] = int((a-1) * (a-2) / 2)


    su = sum(A_product)
    for k in A:
        print(su - A_product[k-1] + A_product_1[k-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 25736
#include<stdio.h>
long long s(long long a,long long b)
{long long k;
if(a<b) 
   {k=a;a=b;b=k;
    }
	return a%b==0? b:s(b,a%b);
 } 
int main()
{
	long long n,a[200],i,x,t;
	 scanf("%lld",&n);
	     for(i=0;i<n;i++)
	       scanf("%lld",&a[i]);
	       
	           for(i=0;i<n-1;i++)
	            {
				  a[i+1]=a[i]/s(a[i],a[i+1])*a[i+1];
				
				}
				printf("%lld",a[n-1]);
				return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from itertools import accumulate
n = int(input())
A = [0] + list(map(int, input().split()))
B = tuple(accumulate(A))
dp = [[-1]*(n+1) for _ in range(n+1)]
def f(i, j):
  if i == j:
    return 0
  if dp[i][j] != -1:
    return dp[i][j]
  if j-i == 1:
    dp[i][j] = A[i]+A[j]
    return dp[i][j]
  res = float("inf")
  for m in range(i, j):
    res = min(res, f(i,m)+f(m+1,j)+(B[j]-B[i-1]))
  dp[i][j] = res
  return res
ans = f(1, n)
print(ans)

Measured memory_bytes: 76140
n = int(input())
a = list(map(int, input().split()))
a += [0]
x = 1000
s = 0
for i in range(n):
  if a[i] < a[i + 1]:
    d = x // a[i]
    s += d
    x -= d * a[i]
  elif a[i] > a[i + 1]:
    x += s * a[i]
    s = 0
print(x)


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	long long memo[n+5][2]={};
	for (int i = 0; i < n-1; ++i)
	{
		for (int j = 0; j < 2; ++j)
		{
			memo[i][j]=1000000000000000LL;
		}
	}
	long long dp[n+5][20][2];
	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < 16; ++j)
		{
			dp[n-1][j][i]=j;
		}
		for (int j = n-2; j >= 0; --j)
		{
			for (int k = 0; k < 16; ++k)
			{
				long long now=a[j]<<(2*k);
				int tmp=0;
				while (now>(a[j+1]<<(2*tmp)))
				{
					++tmp;
				}
				if (tmp<16)
				{
					dp[j][k][i]=dp[j+1][tmp][i]+k;
				}
				else
				{
					dp[j][k][i]=dp[j+1][15][i]+k+(tmp-15)*(n-1-j);
				}
				memo[j][i]=min(memo[j][i],dp[j][k][i]);
			}
		}
		reverse(a,a+n);
	}
	long long ans=1000000000000000LL;
	for (int i = 0; i <= n; ++i)
	{
		ans=min(ans,(long long)i+2LL*(memo[i][0]+memo[n-i][1]));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 67456
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;
    for (auto c : s) if (c == 'o') cnt++;
    YES(cnt + 15 - (int) s.length() >= 8);

    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{

	public static void main (String[] args) {

		Main main = new Main ();
		main.solve();
	}

	private void solve() {

		Scanner sc = new Scanner (System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();

		int time =0;

		int ar = a%10;
		int br = b%10;
		int cr = c%10;
		int dr = d%10;
		int er = e%10;

		int[] list = new int[5];

		if (ar==0) {
			list[0]=9;
		} else {
			list[0]=ar;
		}

		if (br==0) {
			list[1]=9;
		} else {
			list[1]=br;
		}

		if (cr==0) {
			list[2]=9;
		} else {
			list[2]=cr;
		}

		if (dr==0) {
			list[3]=9;
		} else {
			list[3]=dr;
		}

		if (er==0) {
			list[4]=9;
		} else {
			list[4]=er;
		}

		Arrays.sort(list);
		int[] list2 = new int [5];
		if (list[0]==ar) {
			list2=check('a',a,b,c,d,e);
		} else if (list[0]==br) {
			list2=check('b',a,b,c,d,e);
		} else if (list[0]==cr) {
			list2=check('c',a,b,c,d,e);
		} else if (list[0]==dr) {
			list2=check('d',a,b,c,d,e);
		} else if (list[0]==er){
			list2=check('e',a,b,c,d,e);
		} else {
			list2 = check ('1',a,b,c,d,e);
		}

		for (int index=0; index<5; index++) {
			time+=list2[index];
		}

		System.out.println(time);
	}

	private int[] check (char ch, int a, int b, int c, int d, int e) {

		int[] list2 = new int [5];

		switch (ch) {

		case 'a':
			if (b%10!=0) {
				b-=b%10;
				b+=10;
			}
			if (c%10!=0) {
				c-=c%10;
				c+=10;
			}
			if (d%10!=0) {
				d-=d%10;
				d+=10;
			}
			if (e%10!=0) {
				e-=e%10;
				e+=10;
			}
			break;
		case 'b':
			if (a%10!=0) {
				a-=a%10;
				a+=10;
			}
			if (c%10!=0) {
				c-=c%10;
				c+=10;
			}
			if (d%10!=0) {
				d-=d%10;
				d+=10;
			}
			if (e%10!=0) {
				e-=e%10;
				e+=10;
			}
			break;

		case 'c':
			if (a%10!=0) {
				a-=a%10;
				a+=10;
			}
			if (b%10!=0) {
				b-=b%10;
				b+=10;
			}
			if (d%10!=0) {
				d-=d%10;
				d+=10;
			}
			if (e%10!=0) {
				e-=e%10;
				e+=10;
			}
			break;
		case 'd':
			if (a%10!=0) {
				a-=a%10;
				a+=10;
			}
			if (b%10!=0) {
				b-=b%10;
				b+=10;
			}
			if (c%10!=0) {
				c-=c%10;
				c+=10;
			}
			if (e%10!=0) {
				e-=e%10;
				e+=10;
			}
			break;
		case 'e':
			if (a%10!=0) {
				a-=a%10;
				a+=10;
			}
			if (b%10!=0) {
				b-=b%10;
				b+=10;
			}
			if (c%10!=0) {
				c-=c%10;
				c+=10;
			}
			if (d%10!=0) {
				d-=d%10;
				d+=10;
			}
			break;

			default:
		}

		list2[0]=a;
		list2[1]=b;
		list2[2]=c;
		list2[3]=d;
		list2[4]=e;
		return list2;
	}
}


Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX_N 50

using namespace std;

int V[MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> V[i];
  }
  sort(V, V + N);
  double res = 0.5 * (V[0] + V[1]);
  for (int i = 2; i < N; ++i) {
    res = 0.5 * (res + V[i]);
  }
  printf("%f\n", res);
}

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

using namespace std;
#define ll long long;

int k;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>k;
    string s("ACL");
    for(int i=0; i<k; i++)
        cout<<s;
    return 0;
}


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

using namespace std;

int main(){
    int N;
    int cnt[100] = {};
    int c = 0;

    cin >> N;

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

    for(int i = 0; i < N; i++){
        cnt[d[i]-1] += 1;
    }

    for(int i = 0; i < 100; i++){
        if (cnt[i] != 0)
            c += 1;
    }

    printf("%d\n", c);

    return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair <int, int> > adj[MAX];

void dijkstra() {
    priority_queue<pair <int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for (int i=0; i<n; i++) {
        d[i] = INFTY;
        color[i] = INFTY;
    }

    d[0] = 0;
    PQ.push(make_pair(0,0));
    color[0] = GRAY;

    while (!PQ.empty()) {
        pair<int, int> f = PQ.top(); PQ.pop();
        int u=f.second;
        color[u] = BLACK;

        if (d[u] < f.first * (-1)) continue;

        for (int j=0; j<adj[u].size(); j++) {
            int v = adj[u][j].first;
            if ( color[v] == BLACK ) continue;
            if (d[v]>d[u] + adj[u][j].second) {
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1), v));
                color[v] = GRAY;
            }
        }
    }

    for (int i=0; i<n; i++) {
        cout << i << " " << (d[i]==INFTY ? -1 : d[i]) << endl;
    }
}

int main() {
    int k, u, v, c;

    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> u >> k;
        for (int j=0; j<k; j++) {
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}


Measured memory_bytes: 7992
local N, M, X = io.read("*n", "*n", "*n")

local C, A = {}, {}
for i = 1, N do
	C[i] = io.read("*n")
	A[i] = {}
	for j = 1, M do
		A[i][j] = io.read("*n")
	end
end

local function sumList(sum_points, i)
	for j = 1, M do
		sum_points[j] = sum_points[j] + A[i][j]
	end
end

local sum_points = {}
local price = math.huge
-- N is bit length
for pattern = 1, 2^N do
	local price_sum = 0
	for i = 1, M do
		sum_points[i] = 0
	end

	for i = 1, N do
		if bit.band(pattern, 1) == 1 then
			price_sum = price_sum + C[i]
			sumList(sum_points, i)
		end
		pattern = bit.rshift(pattern, 1)
	end

	local isClear = true
	for i = 1, M do
		if X > sum_points[i] then
			isClear = false
			break
		end
	end

	if isClear and price_sum < price then
		price = price_sum
	end
end

print((price == math.huge) and -1 or price)

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



int main(){
    int n;
    cin >> n;
    bool flag=false;
    rep(i,2){
        int a=n%10;
        if(a==9) flag=true;
        n/=10;
    }
    if(flag) cout << "Yes" <<endl;
    else cout << "No" <<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define vi vector<int>
#define Sort(v) sort(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;




int main(){
    vi a(3);
    cin >> a[0] >> a[1] >> a[2];
    
    Sort(a);
    
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
}









Measured memory_bytes: 3164
#include<iostream>
using namespace std;
long long hoge = 1000000007;

int main(){
  int n, m, head = 0;
  // 標準入力
  cin >> n >> m;

  int a[m+1];
  long long s[n+1];
  for ( int i = 0; i < m; i++){ cin >> a[i];}
  a[m] = -1;
  a[m+1] = -1;

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

  // 1段目
  s[0] = 1;
  s[1] = 1;
  // 2段目から始める
  for ( int i = 2; i <= n; i++){
    if (i-2 == a[head] && i-1 == a[head+1]){
      s[i] = 0;
      break;
    } else if (i-2 == a[head] && i-1 != a[head+1]){
      s[i] = s[i-1];
      head++;
    } else if (i-2 != a[head] && i-1 == a[head]){
      s[i] = s[i-2];
    } else {
      s[i] = s[i-2] + s[i-1];
    }

   s[i] = s[i]%hoge;
  }

  cout << s[n]%hoge << endl;

  return 0;
}


Measured memory_bytes: 1408
use std::io::stdin;
use std::time::SystemTime;

#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read<T>() -> T
where T: std::str::FromStr
{
    read_line().parse::<T>().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T>() -> Vec<T>
where T: std::str::FromStr
{
    read_line().split(" ").map(|n| n.parse::<T>().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn read_chars() -> Vec<char>
{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn print_time() -> () {
    println!("{:?}", SystemTime::now());
}

#[allow(unused_variables)]
fn main() {
    let hw: Vec<i64> = read_vec();
    let mut maryoku: Vec<Vec<u64>> = vec![];
    for _ in 0..10 {
        maryoku.push(read_vec());
    }
    
    let mut map: Vec<Vec<i8>> = vec![];
    for _ in 0..hw[0] {
        map.push(read_vec());
    }
    
    for k in 0..10 {
        for i in 0..10 {
            for j in 0..10 {
                let t = maryoku[i][k] + maryoku[k][j];
                if t < maryoku[i][j] {
                    maryoku[i][j] = t;
                }
            }
        }
    }
    
    let mut count = 0;
    for i in 0..hw[0] {
        for j in 0..hw[1] {
            let tt = map[i as usize][j as usize];
            if tt != -1 && tt != 1 {
                let t = maryoku[tt as usize][1];
                count = count + t;
            }
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
W=n1()
ans=10**10
for i in range(0,n-1):
    c1=sum(W[:i+1])
    c2=sum(W[i+1:])
    ans=min(ans,abs(c1-c2))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int MAXN = 2*1e5 + 10;
int v[MAXN],antes[MAXN],depois[MAXN],n;
long long resposta;
int main(){
	stack<ii> pilha;
	cin.tie(0);ios_base::sync_with_stdio(0);
	cin >> n;
	v[0] = v[n+1] = -1;
	for(int i = 1;i<=n;i++){
		cin >> v[i];
	}
	pilha.push(ii(-1,0));
	for(int i = 1;i<=n+1;i++){
		ii davez = ii(v[i],i);
		while(pilha.top() > davez){
			//printf("Depois de %d eh %d\n",pilha.top().second,i);
			depois[pilha.top().second] = i;
			pilha.pop();
		}
		antes[i] = pilha.top().second;
		pilha.push(davez);
	}
	for(int i = 1;i<=n;i++){
		antes[i]++;
		depois[i]--;
		int esq = abs(i - antes[i]) + 1;
		int dir  = abs(depois[i] - i) + 1;
		resposta += 1LL*esq*dir*v[i];
	}
	cout << resposta << endl;
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

// 文字列から数値へ変換して key を生成する
long long getKey(char str[]) {
  long long sum =0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) %M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str); // より高速なscanfを使用
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16040
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int p,q,r;
  cin >> p >> q >> r;
  int ans = p + q + r;
  ans -= max(p,max(q,r));
  printf("%d\n", ans);
  return 0;
}


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

const int MAX_V=101010;
int V,E;

int par[MAX_V]; //　親
int rnk[MAX_V]; // rank, 木の深さ

// V要素で初期化
void init(){
  for(int i=0;i<MAX_V;i++){
    par[i]=i;
    rnk[i]=0;
  }
}

// 木の根を求める
int find(int x){
  if (par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

// ｘとｙの属する集合を併合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rnk[x] < rnk[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}

// ｘとｙが同じ集合に属するかどうか
bool same(int x, int y){
  return find(x) == find(y);
}

vector<pair<int,int> > A;

int main(){
  cin>>V>>E;
  init();
  rep(i,V){
    int a; cin>>a;
    A.push_back(make_pair(a,i));
  }
  rep(i,E){
    int x,y; cin>>x>>y;
    unite(x,y);
  }
  if(V<2*(V-E-1)){
    cout<<"Impossible"<<endl;
    return 0;
  }
  if(E==V-1){
    cout<<0<<endl;
    return 0;
  }
  sort(A.begin(),A.end());
  ll ans=0; int cnt=0;
  set<int> st;
  rep(i,V){
    if(st.count(find(A[i].second))){
      if(cnt<V-E-2){
        ans+=A[i].first;
        cnt++;
      }
    }else{
      st.insert(find(A[i].second));
      ans+=A[i].first;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4212
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int const nmax = 1e5;
int v[1 + nmax];

int main() {

  int n, old, older, inp, ans = 0;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> v[i];
  }
  sort(v+1, v+n+1);
  //cerr << v[n/2+1];
  cout << v[n/2+1] - v[n/2];
}


Measured memory_bytes: 764
#![allow(unused_imports, unused_variables, dead_code, non_snake_case)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

fn main() {
    let cin = stdin(); let cin = cin.lock(); let mut sc = Scanner::new(cin);

    let mut hp: BinaryHeap<i64> = BinaryHeap::new();
    let n: usize = sc.read();
    let mut input = vec![0; n];
    let mut cnt: i64 = 0;
    for i in 0..n {
        let num: i64 = sc.read();
        hp.push(-num);
        cnt += num;
    }
    
    let mut half1 = vec![cnt; n + 1];
    for i in 1..(n+1) {
        let next: i64 = sc.read();
        hp.push(-next);
        let out = hp.pop().unwrap();
        half1[i] = cnt + next + out;
        cnt = half1[i];
        input[i-1] = next;
    }
    
    let mut hp: BinaryHeap<i64> = BinaryHeap::new();
    let mut cnt: i64 = 0;
    for i in 0..n {
        let num: i64 = sc.read();
        hp.push(num);
        cnt += num;
    }

    let mut half2 = vec![cnt; n + 1];
    for i in 1..(n+1) {
        let next: i64 = input[n-1 - (i-1)];
        hp.push(next);
        let out = hp.pop().unwrap();
        half2[n-i] = cnt + next - out;
        cnt = half2[n-i];
    }

    let mut ans = i64::min_value();
    for k in 0..(n+1) { ans = max(ans, half1[k] - half2[k]); }
    println!("{}", ans);
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library

//

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    string s; cin >> s;
    string yyyy = s.substr(0, 4);
    string mm = s.substr(5, 2);
    int year = stoi(yyyy);
    int month = stoi(mm);

    string ans;
    if(year <= 2018){
         ans = "Heisei";
    }
    else if(year > 2019){
        ans = "TBD";
    }
    else if(year == 2019 && month <= 4){
        ans = "Heisei";
    }
    else if(year == 2019 && month > 4){
        ans = "TBD";
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 1000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

typedef long long ll;
// #define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  string s; cin >> s;
  string li[] = {"abc", "acb", "bac", "bca", "cab", "cba"};
  REP(i, 6){
    if(li[i] == s){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}

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

int main() 
{
	long int n,k,i,ans=0;
	cin>>n>>k;
	long int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(i=0;i<k;i++)
	{
	    ans+=a[i];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3636
=begin
1, 受け取った文字列 chars で 各文字配列にする
2, 各文字を ord で文字コードに変換する(https://docs.ruby-lang.org/ja/latest/method/String/i/ord.html)
3, 対象の文字列から"A".ord の文字コード分を引くことで、アルファベット順の0~25の本来の位置を出力する
4, ズラしたい数値 n を 3, の出力にたす
5, "Z"以降のずれを防ぐため %26 であまりを出す
6, 5, の出力に "A".ordの数値を足して文字コードを元に戻す
7, .chrで文字コードを文字に変換する
=end

n = gets.to_i
s = gets.chomp.chars
a = 'A'.ord

puts s.map{|x| ((x.ord - a + n) % 26 + a).chr}.join("")

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


int main() {
  int money;
  cin >> money;
  
  int coins500 = 0;
  int coins5 = 0;

  coins500 = money / 500;
  money -= 500 * coins500;
  coins5 = money / 5;
  cout << 1000 * coins500 + 5 * coins5 << endl;
}

Measured memory_bytes: 256
num, sum = gets.split.map(&:to_i)

max10k = [sum / 10000, num].min
0.upto max10k do |n10k|
  rest_sum = sum - n10k * 10000

  max_5k = [rest_sum / 5000, num - n10k].min
  0.upto max_5k do |n5k|
    rest_sum_inner = rest_sum - n5k * 5000

    n1k = num - n10k - n5k
    if rest_sum_inner / 1000 == n1k
      # 見つかった！
      puts "#{n10k} #{n5k} #{n1k}"
      exit(0)
    end
  end
end

# 見つからなかった
puts "-1 -1 -1"


Measured memory_bytes: 1788
import math

org_in = input()
Z = []
for i in org_in.split():
    Z.append(int(i))
    
A = Z[0]
B = Z[1]
H = Z[2]
M = Z[3]
    
alpha = 2*math.pi * ( 60*H + M ) / 720
beta = 2*math.pi * M / 60
theta = alpha - beta

length = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))

print(length)



Measured memory_bytes: 62352
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
 
#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
 
#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(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
 
ll n;
ll sum[600][60*30];
ll ans[600];
 
void solve(){
    // ll res = 0;
    rep(i,600)rep(j,60*30-1)sum[i][j+1] += sum[i][j];
    FOR(i,1,600){
        ll cnt = 0;
        rep(j,60*30){
            if((sum[i][j] > 0) && (sum[0][j] > 0))cnt++;
            // else cnt = 0;
            // res = max(cnt,res);
        }
		ans[i] += cnt;
    }
    // return res;
}
 
void init(){
    rep(i,600)rep(j,60*30)sum[i][j] = 0;
}
 
ll calc(string s){
    return ((s[0] - '0')*10+(s[1] - '0'))*60 + (s[3] - '0')*10+(s[4] - '0');
}
 
int main(){
    while(cin >> n && n){
		fill(ans,ans+600,0);
        string pre = "";
        ll aans = 0;
        rep(i,n){
            string s,hm,e;
            ll p;
            cin >> s >> hm >> e >> p;
            if(pre != s){
                pre = s;
				solve();
                // ans = max(ans,solve());
				// cout << "!!" << pre << " " << ans << endl;
                init();
            }
            ll num = calc(hm);
            // cout << p << endl;
            if(e == "I")sum[p][num] = 1;
            else sum[p][num] = -1;
        }
        // ans = max(ans,solve());
		solve();
		init();
		FOR(i,1,600)aans = max(aans,ans[i]);
		// cout << "!!" << pre << " " << ans << endl;
        cout << aans << endl;
    }
}


Measured memory_bytes: 11500
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int N, A, B;
  bool flag;
  cin >> N >> A >> B;
  if(B-A == 1){
    cout << "Borys" << endl;
    return 0;
  }else{
    while(1){
      A++;
      if(B-A == 1){
        flag = true;
        break;
      }else{
        B--;
        if(B-A == 1){
          flag = false;
          break;
        }
      }
    }
  }
  if(flag){
    cout << "Alice" << endl;
  }else{
    cout << "Borys" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF 1<<21
using namespace std;

int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0) break;
    int res = INF;
    int i, j;
   
    for (i = 0;; i++){
      int tmp = n;
      tmp -= i*i*i;
      if (tmp<0) break;
      for (j = 0;; j++){
	if (j*j > tmp) break;
      }
      j--;
      tmp -= j*j;
      res = min(res, i+j+tmp);
    }

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

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

int main() {

	int A, B;
	cin >> A >> B;

	int ans = A - (B * 2);
	if (ans < 0) { ans = 0; }
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
Q=int(input())
d=[0]*(10**5 +1)#各数字の個数
for i in A:
  d[i]+=1

for i in range(Q):
  B,C=map(int,input().split())
  s += (C-B)*d[B]
  print(s)
  d[C]+=d[B]
  d[B]=0

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

typedef long long ll;
#define mod 1000000007

int main()
{
    string t, s;

    cin >> s >> t;

    int k = t.size();

    int ans = t.size();

    for(int i = 0; i+k-1 < s.size(); i++){
        int c = 0;
        for(int j = 0; j < k; j++){
            if(t[j] != s[i+j])
                c++;
        }
        ans = min(ans, c);
    }

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

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

ll mul(ll a, ll b) { return (a*b)%M; }
ll mod_pow(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b&1) r = mul(r, a);
    b >>= 1;
    a = mul(a, a);
  }
  return r;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n;
  cin >> n;
  ll ans = mod_pow(10,n)-mod_pow(9,n)-mod_pow(9,n)+mod_pow(8,n);
  ans = (ans%M+M)%M;
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i,j,k,n,m,l,count1=0;
void ABC130(void);
void ABC131(void);
void ABC132(void);
void ABC133(void);
void ABC134(void);
void ABC135(void);
void ABC136(void);
void ABC137(void);
void ABC138(void);
void ABC139(void);

int main(void){
    ABC139();
}

void ABC139(){
    int a,b,sum=1;
    cin>>a>>b;
    while(sum<b){
        sum=sum-1+a;
        count1++;
    }
    cout<<count1<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>

using namespace std;

int main() {
    char s[10];
    cin >> s;

    int x = 753;
    int res = 1000;

    size_t l = strlen(s);
    int tmp;

    for (int i = 0; i < l - 2; i++) {
        tmp = abs(100 * static_cast<int>(s[i]-'0') + 
               10 * static_cast<int>(s[i+1]-'0') +
               static_cast<int>(s[i+2]-'0') - x); 
        res = res > tmp ? tmp : res; 
    }
    cout << res << endl;
}


Measured memory_bytes: 256