akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<50;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

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

  int h,w,k;
  cin>>h>>w>>k;
  int sx,sy,gx,gy;
  cin>>sx>>sy>>gx>>gy;
  sx--;sy--;gy--;gx--;
  swap(sx,sy);swap(gx,gy);
  vector<string> s(h);
  cin>>s;

  constexpr ll dx[]={1,0,-1,0,1,1,-1,-1};
  constexpr ll dy[]={0,1,0,-1,1,-1,1,-1};
  using T3 = tuple<ll,ll,ll>;
  using T4 = tuple<ll,ll,ll,ll>;

  vector dist(h,vector<ll>(w,INF));
  auto out = [&](int y,int x){return y<=-1||y>=h||x<=-1||x>=w;};
  auto cmp = [](auto a,auto b){return get<2>(a)>get<2>(b);};
  queue<T3> que;
  //priority_queue<T3,vector<T3>,decltype(cmp)> que(cmp);
  que.emplace(sy,sx,0);
  dist[sy][sx] = 0;
  while(!que.empty()){
    auto [y,x,c] = que.front();
    que.pop();
    dump(y,x,c);
    rep(i,4){
      for(int j=1;j<=k;++j){
        int ny = y+dy[i]*j;
        int nx = x+dx[i]*j;
        int nc = c+1;
        if(out(ny,nx))break;
        if(s[ny][nx]=='@')break;
        if(dist[ny][nx]<=dist[y][x])break;
        if(chmin<ll>(dist[ny][nx],nc))que.emplace(ny,nx,nc);
      }
    }
  }
  if(dist.at(gy).at(gx)==INF)cout<<-1<<endl;
  else cout<<dist.at(gy).at(gx)<<endl;


}


Measured memory_bytes: 19832
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

long long MOD = 1e9+7;

template <typename T> class Factorial {
  public:
    vector<T> fact;
    vector<T> factinv;
    Factorial(int N);
    static T bipow(T c, T n);
    static T square(T n);
    T conv(T n, T m) const;
    T perm(T n, T m) const;
};

template <typename T> Factorial<T>::Factorial(int N) : fact(N+1), factinv(N+1) {
  fact[0] = 1;
  for (int i = 1; i < N+1; i++) {
    fact[i] = fact[i-1]*static_cast<T>(i)%MOD;
  }
  factinv[N] = bipow(fact[N], MOD-2);
  for (int i = N; i > 0; i--) {
    factinv[i-1] = factinv[i]*static_cast<T>(i)%MOD;
  }
}

template <typename T> T Factorial<T>::bipow(T c, T n) {
  if (n == 0) {
    return 1;
  } else if(n == 1) {
    return c;
  } else if(n%2 == 0) {
    return square(bipow(c, n/2))%MOD;
  } else {
    return (static_cast<T>(c)*square(bipow(c, (n-1)/2)))%MOD;
  }
}

template <typename T> T Factorial<T>::square(T n) {
  return static_cast<long long>(n)*n%MOD;
}

template <typename T> T Factorial<T>::conv(T n, T m) const {
  if (n < m) {
    return 0;
  }
  return (((static_cast<long long>(fact[n])*factinv[m])%MOD)*factinv[n-m])%MOD;
}

template <typename T> T Factorial<T>::perm(T n, T m) const {
  if (n < m) {
    return 0;
  }
  return (static_cast<long long>(fact[n])*factinv[n-m])%MOD;
}

void solve(long long N, long long A, long long B, long long C){
  Factorial<long long> f(2*N);
  long long ans = 0;
  long long invab = Factorial<long long>::bipow(A+B, MOD-2);
  long long pa, pb;
  pa = A * invab % MOD;
  pb = B * invab % MOD;
  long long invp = 100 * invab % MOD;
  long long t;

  for (long long i = N; i <= 2*N-1; i++) {
    t = Factorial<long long>::bipow(pa, N) * Factorial<long long>::bipow(pb, i-N) % MOD;
    t += Factorial<long long>::bipow(pb, N) * Factorial<long long>::bipow(pa, i-N) % MOD;
    t %= MOD;
    t *= f.conv(i-1, i-N);
    t %= MOD;
    ans += t * (i * invp % MOD) % MOD;
    ans %= MOD;
  }

  std::cout << ans << std::endl;
}

int main(){
  long long C;
  long long N;
  long long A;
  long long B;
  scanf("%lld",&N);
  scanf("%lld",&A);
  scanf("%lld",&B);
  scanf("%lld",&C);
  solve(N, A, B, C);
  return 0;
}


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

#define x first
#define y second
#define x1 X1 
#define x2 X2
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
inline int read ()
{
	int sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

const int Maxn = 2e5 + 100;

int N, A[Maxn], Dp[Maxn];

int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	N = read();
	int ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		A[i] = read();
		Chkmax (Dp[A[i]], Dp[A[i] - 1] + 1);
		Chkmax (ans, Dp[A[i]]);
	}
	cout<<N - ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << a[n-1]-a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    } 
    sort(v.begin(),v.end());
    int sum=0;
    for(int i=0;i<v.size();i++)
    {
        sum+=v[i];
    }
    int nonten=sum;
    for(int i=0;i<v.size();i++){
        if(v[i]%10!=0){
            nonten=v[i];
            break;
        }
    }
    int result1=sum-nonten;
    int index=0;
    while(index<v.size()&&sum%10==0){
        sum-=v[index];
        index++;
    }
    cout<<max(sum,result1);
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */

int main(){
    ii(n); lint W, w0, v0; cin >> W >> w0 >> v0;
    vector<lint> vec[4]; vec[0].push_back(v0);
    rep(i, n-1){
        lint w, v; cin >> w >> v;
        vec[w - w0].push_back(v);
    }
    
    int vs[4];
    rep(i, 4){
        vs[i] = vec[i].size();
        sort(all(vec[i]), greater<lint>());
        rep(j, vs[i]-1) vec[i][j+1] += vec[i][j];
        vec[i].insert(vec[i].begin(), 0);
    }

    lint ans = 0;
    rep(i, vs[0]+1) rep(j, vs[1]+1) rep(k, vs[2]+1) rep(l, vs[3]+1){
        lint ww = (i+j+k+l)*w0 + j + 2*k + 3*l;
        if(ww <= W){
            lint vv = vec[0][i] + vec[1][j] + vec[2][k] + vec[3][l];
            ans = max(ans, vv);
        }
    }
    out(ans);
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int K,S;
int A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K>>S;
	ll ret=0;
	for(A=0;A<=K;A++) {
		for(B=0;B<=K;B++) {
			int C=S-A-B;
			if(C>=0 && C<=K) ret++;
		}
	}
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
 
    int n, k;
    cin >> n >> k;
    vector<int> lis;
    int answer = 0;
    while(n--){
        int p;
        cin >> p;
        lis.push_back(p);
        sort(lis.begin(), lis.end());
    }
    for(int i=0; i<k; i++){
        answer += lis[i];
    }
    cout << answer;
}

Measured memory_bytes: 3672
N = int(input())
C = list(map(int, input().split()))
C.sort()

ans = 0
mod = 10**9 + 7

for l in range(N):
    r = N - l - 1
    if r > 0:
        ans += C[l] * (pow(2, r-1, mod) * r + pow(2, r, mod)) * pow(2, l, mod)
    else:
        ans += C[l] * (pow(2, r, mod)) * pow(2, l, mod)
        
print(int(ans * pow(2, N, mod)) % mod)




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

class Hello{

    public static void Main(){
    
        long h;
    
      
        h = long.Parse(Console.ReadLine());
        var atkc = Attack(h);
        
        Console.WriteLine(Calc(atkc));
    }
    
    public static long Attack(long h){
        
        if(h <= 1){
            return 0;    
        }
        else{
            
            var sum = Attack(h/2);
            return sum + 1;            
        }
    } 
   
    public static long Calc(long n)
    {
        if(n == 0) return 1;
        else
        return (long)Math.Pow(2,n) + Calc(n-1); 
    }
    
}

Measured memory_bytes: 13140
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    (d1 : d2 : _) <- drop (n `div` 2 - 1) . sort <$> getIntList
    print $ if d1 == d2 then 0 else d2 - d1

Measured memory_bytes: 18812
n, m = map(int,input().split())
students = [None]*n
points = [None]*m
for i in range(n):
  students[i] = tuple(map(int,input().split()))
for i in range(m):
  points[i] = tuple(map(int,input().split()))

ans = []
for s in students:
  tmp = []
  for p in points:
    tmp.append(abs(s[0] - p[0]) + abs(s[1] - p[1]))
  ans.append(tmp.index(min(tmp)) + 1)
for i in range(n):
  print(ans[i])

Measured memory_bytes: 3064
#include <iostream>
typedef long long ll;
using namespace std;

int main() {
  int n,k;
  cin >> n >> k;

  if(k & 1) {
    ll ans = n / k;
    cout << ans * ans * ans << endl;
  }
  else {
    ll ans = n / k;
    ll ans2 = (2 * n + k) / (2 * k);
    cout << ans * ans * ans + ans2 * ans2 * ans2<< endl;
  }
}
    


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

int main() {
    int n = 0;
    int x;
    cin >> n;

    if(n < 600) n = 8;
    else if(n < 800) n = 7;
    else if(n < 1000) n = 6;
    else if(n < 1200) n = 5;
    else if(n < 1400) n = 4;
    else if(n < 1600) n = 3;
    else if(n < 1800) n = 2;
    else if(n < 2000) n = 1;
    cout << n << endl;
}

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

int main() {
  int n, x = 0, result = 0;
  string s;
  cin >> n >> s;


  for (int i = 0; i < n; i++){
    if(s[i] == 'I'){
      x += 1;
      if(x > result){
        result = x;
      }
    }else if (s[i] == 'D'){
      x -= 1;
    }
  }
  
  cout << result << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string s; cin>>s;
    int ans=700;
    REP(i,s.size()){
        if(s[i]=='o') ans+=100;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

N, H = map(int, input().split())

A = []
B = []

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A = sorted(A)[::-1]
B = sorted(B)[::-1]

ret = 0
if B[0] < A[0]:
    if H % A[0] == 0: ret = H // A[0]
    else: ret = H // A[0] + 1
    H = 0
else:
    for b in B:
        if b < A[0]:
            if H%A[0] == 0: ret += H // A[0]
            else: ret += H // A[0] + 1
            H = 0
            break
        else:
            ret += 1
            H -= b

        if H <= 0:
            break

    if H > 0:
        if H%A[0] == 0: ret += H // A[0]
        else: ret += H // A[0] + 1


print(ret)


Measured memory_bytes: 89952
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i = 0; i < N; i++){
        cin >> S[i];
    }

    long long ans = 0;
    map<string, bool> M;
    vector<long long> C(5, 0);
    for(int i = 0; i < N; i++){
        if(S[i][0] == 'M' || S[i][0] == 'A' || S[i][0] == 'R' || S[i][0] == 'C' || S[i][0] == 'H'){
            if(M[S[i]] == false){
                M[S[i]] = true;

                if(S[i][0] == 'M'){
                    C[0]++;
                }else if(S[i][0] == 'A'){
                    C[1]++;
                }else if(S[i][0] == 'R'){
                    C[2]++;
                }else if(S[i][0] == 'C'){
                    C[3]++;
                }else if(S[i][0] == 'H'){
                    C[4]++;
                }
            }
        }
    }

    for(int i = 0; i < 5; i++){
        for(int j = i+1; j < 5; j++){
            for(int k = j+1; k < 5; k++){
                if(C[i] != 0 && C[j] != 0 && C[k] != 0){
                    ans += C[i] * C[j] * C[k];
                }
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 17152
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	int x,y;
	scanf("%d%d",&x,&y);
	if(x == y){
		printf("0");
		return 0;
	}
	if( x == 0 ){
		if(y > 0){
			printf("%d",y - x);
		}
		if(y < 0){
			printf("%d",x - y + 1);
		}
	}
	if(y == 0){
		if(x < 0){
			printf("%d",y - x);
		}
		else{
			printf("%d",x + 1);
		}
	}
	if(x > 0 && y > 0){
		if(x < y){
			printf("%d",y - x);
		}
		else{
			printf("%d",x - y + 2);
		}
	}
	else if(x > 0 && y < 0){
		if(x >= -y){
			printf("%d", abs(x)-abs(y) + 1);
		}
		else{
			printf("%d", abs(y) - abs(x) + 1);
		}
	}
	else if(x < 0 && y > 0){
		if(abs(x) >= abs(y)){
			printf("%d", abs(x) - abs(y) + 1);
		}
		else{
			printf("%d", abs(y) - abs(x) + 1);
		}
	}
	else if( x < 0 && y < 0){
		if(x < y){
			printf("%d", abs(x) - abs(y) );
		}
		else{
			printf("%d",abs(y) - abs(x) + 2);
		}
	}
	return 0;
}

Measured memory_bytes: 256
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    m1,d1 = map(int, input().strip().split())
    # m2,d2 = map(int, input().strip().split())
    smksmri=[4,6,9,11]
    soreigai=[1,3,5,7,8,10,12]
    if d1==28:
        if m1==2:
            print(1)
            return
        elif m1!=2:
            print(0)
            return
        else:
            try:
                raise Exception
            except:
                traceback.print_exc("error0!")
    if d1==30:
        if (m1 in smksmri):
            print(1)
            return
        elif (not (m1 in smksmri)):
            print(0)
            return 
        else:
            try:
                raise Exception
            except:
                traceback.print_exc("error1!")
    elif d1==31:
        if (m1 in soreigai):
            print(1)
            return
        elif (not (m1 in soreigai)):
            print(0)
            return 
        else:
            try:
                raise Exception
            except:
                traceback.print_exc("error2!")
    elif d1!=28 and d1!=30 and d1!=31:
        print(0)
        return 
    else:
        print(0)
        return
        try:
            raise Exception
        except:
            traceback.print_exc("error3!")


    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 66028
#include<bits/stdc++.h>
using namespace std;
int col[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
int main(){
	int x,y;cin>>x>>y;
	if(col[x]==col[y])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include<iostream>
using namespace std;

struct Point{
	double x,y;
};

int main(){

	int n,m,checkTable[101],path[101],id,start,goal,count,min_index;
	double distance[101][101],x,y,calc[101][101],min_value;
	bool canGO[101];
	Point table[101];
	stack<int> S;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i=1; i <= n; i++){
			scanf("%d %lf %lf",&id,&x,&y);
			table[id].x = x;
			table[id].y = y;
		}

		for(int i = 1; i <= n; i++){
			for(int k = 1; k <= n; k++){
				distance[i][k] = sqrt((table[i].x-table[k].x)*(table[i].x-table[k].x)+(table[i].y-table[k].y)*(table[i].y-table[k].y));
			}
		}

		scanf("%d",&m);

		for(int i = 1; i <= m; i++){
			scanf("%d %d",&start,&goal);

			for(int k = 1; k <= n; k++){
				checkTable[k] = 0;
				if(distance[start][k] < 50 || fabs(distance[start][k] - 50) < 0.00000001){
					canGO[k] = true;
				}else{
					canGO[k] = false;
				}
				path[k] = start;
				for(int p = 1; p <= n; p++)calc[k][p] = distance[k][p];
			}

			count = 1;
			checkTable[start] = 1;

			while(count < n){
				min_value = 1000000000;

				for(int k = 1; k <= n; k++){
					if(checkTable[k] == 0 && canGO[k] == true && calc[start][k] < min_value){
						min_value = calc[start][k];
						min_index = k;
					}
				}

				if(min_value == 1000000000)break;

				checkTable[min_index] = 1;
				count++;

				for(int p = 1; p <= n; p++){
					if((canGO[p] == false || calc[start][p] > calc[start][min_index]+calc[min_index][p]) && (distance[min_index][p] < 50 || fabs(distance[min_index][p] - 50) < 0.00000001)){
						calc[start][p] = calc[start][min_index]+calc[min_index][p];
						canGO[p] = true;
						path[p] = min_index;
					}
				}
			}

			if(canGO[goal] == false)cout<<"NA"<<endl;
			else{
				int t = goal;
				while(true){
					S.push(t);
					t = path[t];
					if(t == start)break;
				}
                cout<<start;
				while(!S.empty()){
                    cout<<" "<<S.top();
					S.pop();
				}
				cout<<endl;
			}
		}
	}


	return 0;
}


Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define print(v) { cout<<#v<<": [ "; for(auto _ : v) cout<<_<<", "; cout<<"]"<<endl; }
typedef long long ll;

int main(void){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    rep(i,n-1) a[i+1] += a[i];

    ll res = a[n-1];
    int left = 0, right = 0;
    rep(m,n){
        while(left < m){
            if(a[left]>=a[m]-a[left]) break;
            left++;
        }
        right = max(right,m+1);
        while(right < n-1){
            if(a[right]-a[m]>=a[n-1]-a[right]) break;
            right++;
        }

        for(int l = max(left-3,0); l < min(m,left+3); l++){
            for(int r = max(right-3,m+1); r < min(right+3,n-1); r++){
                vector<ll> seg = {a[l],a[m]-a[l],a[r]-a[m],a[n-1]-a[r]};
                sort(all(seg));
                res = min(res, seg[3]-seg[0]);
            }
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1792
import itertools
n,m,q = map(int,input().split())
num = [i for i in range(1,m+1)]
q_list = []
for i in range(q):
  q_list.append(list(map(int,input().split())))

a_cand = list(itertools.combinations_with_replacement(num, n))
count_list = []
for a in a_cand:
    count = 0
    for q in q_list:
      if a[q[1]- 1] - a[q[0] - 1] == q[2]:
        count += q[3]
        
    count_list.append(count)
  
print(max(count_list))




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

void swap(int *a, int *b){
    int t=*a;
    a=b;
    *b=t;
}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a>b) swap(a,b);
    if(b>c) swap(b,c);
    if(a>b) swap(a,b);
    cout << a << ' ' << b << ' ' << c << endl;
    return 0;
}


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

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

long long MOD = 1000000000 + 7;

int main(){
  int N;
  ll K;
  cin >> N >> K;
  int log_K = floor(log2(K));
  cerr << N << " " << log_K << endl;
  vector<vector<int>> next(log_K + 1, vector<int>(N));

  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    cerr << i << " : " << tmp << endl;
    next.at(0).at(i) = tmp-1;
  }

  for(int k = 0; k < log_K; k++){
    for(int i = 0; i < N; i++){
      if(next[k][i] == -1){
        next[k+1][i] = -1;
      } else { 
        next[k+1][i] = next[k][next[k][i]];
        // cerr << k+1 << " " << i << " " << next[k+1][i] << endl;
      }
    }
  }

  int ans = 0;
  for(ll k = log_K; k >= 0; k--){
    if((K>>k)&1){
      ans = next[k][ans];
    }
  }
  cout << ans+1<< endl;

}

Measured memory_bytes: 51268
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

const LL INF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 10000;

vector<vector<int>> e[53];
int c[53], d[53];
LL ans[53]{0, 1}, dis[51][10001];

int main()
{
	int n, m, s;
	cin >> n >> m >> s;
	rep(i, m) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		e[u].push_back({v, a, b});
		e[v].push_back({u, a, b});
	}
	Rep(i, n) cin >> c[i] >> d[i];
	priority_queue<vector<LL>> q;
	memset(dis, 0x3f, sizeof dis);
	s = min(s, MAX);
	q.push({0, -s, 1});
	dis[1][s] = 0;
	int cnt = n - 1;
	while(true) {
		auto x = q.top(); q.pop();
		int p = x[2];
		if(ans[p] == 0) {
			ans[p] = -x[0];
			if(--cnt == 0) break;
		}
		if(dis[p][-x[1]] < -x[0]) continue;
		LL coin = min(c[p]-x[1], (LL)MAX), t = d[p] - x[0];
		if(t < dis[p][coin]) {
			q.push({-t, -coin, p});
			dis[p][coin] = t;
		}
		for(auto& e0: e[p]) {
			coin = -(x[1] + e0[1]); t = e0[2] - x[0];
			if(coin >= 0 && t < dis[e0[0]][coin]) {
				q.push({-t, -coin, e0[0]});
				dis[e0[0]][coin] = t;
			}
		}
	}
	for(int i = 2; i <= n; ++i) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 27680
#include <iostream>
#include <float.h>
using namespace std;
using ll=long long;

int main(){
	double N;
	double K;
	cin>>N>>K;
	double an=0;
	for(double i=1;i<=N;i++){
		double now=i;
		double p=1.0/N;
		while(now<K){
			now*=2.0;
			p/=2.0;
		}
		an+=p;
	}
	printf("%.16f", an);
	return 0;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    res = 0
    for i in range(2, int(-(-(n ** 0.5) // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            # ここでcnt に対して <= n(n+1)//2 となるn を加える。
            add = int((2 * cnt) ** 0.5)
            if cnt >= add * (add + 1) // 2:
                res += add
                # print(add)
            else:
                # print(add - 1)
                res += add - 1

    if temp != 1:
        res += 1
        # arr.append([temp, 1])
    return res


n = int(input())
print(factorization(n))


Measured memory_bytes: 9484
/**
 *    author:  [itmo] enot.1.10
 *    created: 23.10.2016 15:26:20       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 5e5 + 10;
const int mod = 1e9 + 7;


int a[N];
int u[N];
int b[N], bc = 0;

int fact[N];
int rfact[N];

int t[N];

inline void upd(int x, int dx)
{
    x++;
    for (; x < N; x += x & -x) t[x] += dx;
}

inline int get(int x)
{
    x++;
    int res = 0;
    for (; x > 0; x -= x & -x) res += t[x];
    return res;
}

int t2[N];

inline void upd2(int x, int dx)
{
    x++;
    for (; x < N; x += x & -x) t2[x] += dx;
}

inline int get2(int x)
{             
    x++;
    int res = 0;
    for (; x > 0; x -= x & -x) res += t2[x];
    return res;
}

int rev(int x, int m)
{
    if (x == 1) return 1;
    return (1 - rev(m % x, x) * (ll)m) / x + m;
}

int cnk(int n, int k)
{
    return fact[n] * (ll)rfact[k] % mod * rfact[n - k] % mod;
}

int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    fact[0] = 1;
    for (int i = 1; i < N; ++i) fact[i] = fact[i - 1] * (ll)i % mod;
    for (int i = 0; i < N; ++i) rfact[i] = rev(fact[i], mod);

    int res = 0;
    int n;
    scanf("%d", &n);
    forn(i, n) scanf("%d", a + i);
    forn(i, n) a[i]--;
    forn(i, n) if (a[i] != -1) u[a[i]] = 1;
    forn(i, n) if (!u[i]) b[bc++] = i;

    forn(i, n) if (!u[i]) upd2(n - i, 1);

    int sumless = 0;
    int f = 0;    
    for (int i = n - 1; i >= 0; --i)
    {
        if (a[i] >= 0)
        {
            int lss = get(a[i]);
            //for (int j = i + 1; j < n; ++j) if (a[j] != -1 && a[j] < a[i]) lss++;
            int big = get2(n - a[i]);
            int small = bc - big;
            int val = cnk(bc, f) * (ll)lss % mod;
            if (bc >= 1 && f > 0) val = (val + cnk(bc - 1, f - 1) * (ll)small) % mod;
            res = (res + val * (ll)fact[f] % mod * (ll)fact[bc - f] % mod * fact[n - i - 1]) % mod;
            upd(a[i], 1);
            sumless = (sumless + get2(n - a[i])) % mod;
        }
        else
        {
            int add = 0;

            int sum = bc * (ll)(bc - 1) % mod * rev(2, mod) % mod;
            int val = cnk(bc - 1, f) * (ll)sumless % mod;
            if (bc >= 2 && f > 0) val = (val + cnk(bc - 2, f - 1) * (ll)sum) % mod;
            
            res = (res + val * (ll)fact[f] % mod * fact[bc - 1 - f] % mod * fact[n - i - 1]) % mod;
            f++;
        }
    }
    res = (res + fact[bc]) % mod;
    printf("%d\n", res);
            
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


Measured memory_bytes: 13696
//wawando's template

#include <iostream>
#include <string>
#include <fstream>
#include <functional>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <set>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>  //clock_t , clock() , CLOCKS_PER_SEC
#include <cstring>
#include <cctype>
#include <climits> // LLONG_MAX , LLONG_MIN , INT_MAX , INT_MIN

//MACROS
#define pb              push_back
#define mp              make_pair
#define INF             1000000000     //1 billion safer for floyd warshall, avoid overflow

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios::sync_with_stdio(false); cin.tie(0);
  int N;
  string S;

  cin >>N;
  cin >>S;
  int bcnt[200010], wcnt[200010];
  memset(wcnt, 0, sizeof wcnt);
  memset(bcnt, 0, sizeof bcnt);
  for(int i = 0; i < N; i++) {
    if(S[i] == '.') wcnt[i]++;
    if(S[i] == '#') bcnt[i]++;
    if(i > 0) {
      bcnt[i] += bcnt[i-1];
      wcnt[i] += wcnt[i-1];
    }
  }
  int ans = N;
  for(int i = 0; i < N; i++) {
    //0-(i) = white
    //(i+1)-(N-1) = black
    int wr = 0, br = 0;
    br = bcnt[i];
    wr = wcnt[N-1] - wcnt[i];
    ans = min(ans, br + wr);
  }
  //all black
  ans = min(ans, wcnt[N-1]);
  cout <<ans <<endl;
  return 0;



}




Measured memory_bytes: 2196
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

ll pow5(ll x) {
    return x * x * x * x * x;
}

int main() {
    fastio();

    ll x;
    cin >> x;

    for (ll a = -120; a <= 120; a++) {
        for (ll b = -120; b <= 120; b++) {
            if (pow5(a) - pow5(b) == x) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

struct v {
    int to, d;
    v(int to, int d) :to(to), d(d) {}
};

vector<int> pos;
vector<vector<v>> link;

bool check(int p) {
    for(auto t:link[p]) {
        if(pos[t.to]==INT_MIN) {
            pos[t.to]=pos[p]+t.d;
            if(!check(t.to)) return false;
        } else if(pos[t.to]!=pos[p]+t.d) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin>>n>>m;
    pos.resize(n+1, INT_MIN);
    link.resize(n+1);

    for(int i=0; i<m; i++) {
        int l, r, d;
        cin>>l>>r>>d;
        link[l].emplace_back(r, d);
        link[r].emplace_back(l, -d);
    }
    for(int i=1; i<=n; i++) {
        if(pos[i]==INT_MIN) {
            pos[i]=0;
            if(!check(i)) {
                cout<<"No\n";
                return 0;
            }
        }
    }
    cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int k,a,b;
  cin >> k >> a >> b;
  bool f=false;
  for(int i=a; i<=b; i++) if(i%k==0)f=true;
  if(f) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3600
N = int(input())
h = list(map(int, input().split()))
dp = [10 ** 10] * N
# dp[n]はあとnのところからのN-1に行くのに支払うコストの最小値
dp[0] = 0
dp[1] = abs(h[N-1]-h[N-2])
for n in range(0, N-2):
    dp[n+2] = min(dp[n+1]+abs(h[(N-1)-(n+2)]-h[(N-1)-(n+1)]),
                  dp[n]+abs(h[(N-1)-(n+2)]-h[(N-1)-n]))
print(dp[N-1])


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

int main() {
    int N, K;
    cin >> N >> K;
    int n = 1;
    for (int i = 0; i < N; ++i) {
        if(K > n) {
            n *= 2;
        } else {
            n += K;
        }
    }
    cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()

//use (__int128)to extend ll range
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout," ");
inline ll modadd(ll n,ll m,ll mod){
    ll sum = ((n+m)%mod+mod)%mod;
    return sum;
} 
inline ll modsub(ll n,ll m, ll mod){
    ll diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}
inline ll modpro(ll n,ll m,ll mod){
    ll pro = ((n*m)%mod+mod)%mod;
    return pro;
}
inline ll pow(int x,int y){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
inline ll powmod(ll x,ll y,ll mod){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}
ll min(ll a, ll b){
   if(a>b){
       return b;
   }
   return a;
}

ll max(ll a, ll b){
   if(a>b){
       return a;
   }else return b;
}
 
bool pairdec(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 		if(a.fi!=b.fi)
       	return (a.fi> b.fi);
		else return a.se>b.se;  
} 
ll power(ll x, ll y, ll mod) 
{ 
    ll res = 1; 
    x = x%mod; 
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % mod; 
  
        y = y >> 1;
        x = (x * x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll a, ll mod) 
{ 
    return  powmod(a, mod - 2, mod); 
} 
ll modFact(ll n, ll mod) 
{ 
    if (n >=mod) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) %mod; 
  
    return result; 
} 
//cout<<setprecision(9)<<fixed<<sum<<endl; --- precision for double numbers
//copy(v.beg,v.en,outp);
//-----comparision for pairs------
 
// bool comp(const pair<int,int>pia,const pair<int,int>pib)
// {
// 	if(pia.fi==pib.fi) return pia.se>pib.se;
// 	else return pia.fi>pib.fi;
// }

const ll N=1e9+7;
int main()
{
    ll n;
    cin>>n;
    ll sum=1000*(n/500);
    n=(n%500);
    sum+=(5*(n/5));
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

struct node {
    ll w, v;
};

int main() {
    INIT;

    ll N, W;
    cin >> N >> W;

    vector<node> a;
    rep(i, N) {
        node p;
        cin >> p.w >> p.v;
        a.push_back(p);
    }

    vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
    rep(i, N) {
        rep(j, W + 1) {
            if (j < a[i].w) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - a[i].w] + a[i].v);
            }
        }
    }

    // rep(i, N + 1) {
    //     rep(j, W + 1) { cout << dp[i][j] << " "; }
    //     cout << endl;
    // }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 83108
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
int main() {
	int n;
	while(scanf("%d",&n),n) {
		UnionFind UF(26);
		int in[26]={0},out[26]={0};
		for(int i=0;i<n;i++) {
			char str[33];
			scanf("%s",str);
			out[str[0]-'a']++;
			in[str[strlen(str)-1]-'a']++;
			UF.unionSet(str[0]-'a',str[strlen(str)-1]-'a');
		}
		bool OK=true;
		for(int i=0;i<26;i++) {
			for(int j=0;j<26;j++) {
				if((in[i]||out[i])&&(in[j]||out[j])&&!UF.findSet(i,j)) OK=false;
			}
		}
		if(!OK) {printf("NG\n"); continue;}
		for(int i=0;i<26;i++) {
			if(in[i]!=out[i]) OK=false;
		}
		printf("%s\n",OK?"OK":"NG");
	}
}

Measured memory_bytes: 1020
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

ans = [0]*N
for a in A:
	ans[a-1] += 1

print(*ans, sep="\n")


Measured memory_bytes: 33884
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Parser parser = new Parser();

        int A = parser.parseInt();
        int B = parser.parseInt();
        int C = parser.parseInt();
        int X = parser.parseInt();
        int Y = parser.parseInt();

        int minVal = Math.min(X, Y);
        System.out.println(minVal * Math.min(A + B, 2 * C) + (X - minVal) * Math.min(A, 2 * C) + (Y - minVal) * Math.min(B, 2 * C));
    }
}

class Parser {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final Iterator<String> stringIterator = br.lines().iterator();
    private static final Deque<String> inputs = new ArrayDeque<>();

    void fill() throws NoSuchElementException {
        if(inputs.isEmpty()){
            if(!stringIterator.hasNext()) throw new NoSuchElementException();
            inputs.addAll(Arrays.asList(stringIterator.next().split(" ")));
        }
    }

    Integer parseInt() throws NoSuchElementException {
        fill();
        if(!inputs.isEmpty()) {
            return Integer.parseInt(inputs.pollFirst());
        }
        throw new NoSuchElementException();
    }

    Double parseDouble() throws NoSuchElementException {
        fill();
        if(!inputs.isEmpty()) {
            return Double.parseDouble(inputs.pollFirst());
        }
        throw new NoSuchElementException();
    }

    String parseString() {
        fill();
        String string = inputs.pollFirst();
        if(string == null){
            throw new NoSuchElementException();
        }
        return string;
    }

}


Measured memory_bytes: 21332
#!/usr/bin/env ruby
# coding: utf-8

al1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
al2 = {}
al1.split(//).each_with_index do |ch, index|
  al2[ch] = index
end

n = ARGF.gets.to_i
s1 = ARGF.gets.chomp

s2 = s1.split(//).map do |ch|
  al1[(al2[ch] + n) % 26]
end.join("")

puts s2


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

int main() {
  string S,T;
  cin >> S>>T;
  sort(S.begin(),S.end());
  sort(T.begin(),T.end());
  reverse(T.begin(),T.end());
  if(S<T) cout << "Yes" << endl;
  else cout << "No" << endl;

}


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

int main(){
    int s,w;
    cin >> s>>w;
    if(w>=s){
        cout << "unsafe"<< endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long A, long B, long Q, long[] s, long[] t, long[] x) {
    const lWall = [long.min / 8, long.min / 8 + 1];
    const rWall = [long.max / 8 - 1, long.max / 8];

    auto shrines = assumeSorted(lWall ~ s ~ rWall);
    auto temples = assumeSorted(lWall ~ t ~ rWall);
    
    alias lShrine = (long pos) => shrines.lowerBound(pos).back;
    alias rShrine = (long pos) => shrines.upperBound(pos).front;
    alias lTemple = (long pos) => temples.lowerBound(pos).back;
    alias rTemple = (long pos) => temples.upperBound(pos).front;

    foreach (pos; x) {
        const ls = lShrine(pos);
        const lt = lTemple(pos);
        const rs = rShrine(pos);
        const rt = rTemple(pos);

        writeln(min(
            // ls -> llt
            pos - lTemple(ls),
            // lt -> lls
            pos - lShrine(lt),
            // ls -> rt
            pos + rt - 2 * ls,
            // lt -> rs
            pos + rs - 2 * lt,
            // rs -> rrt
            rTemple(rs) - pos,
            // rt -> rrs
            rShrine(rt) - pos,
            // rs -> lt
            2 * rs - lt - pos,
            // rt -> ls
            2 * rt - ls - pos
        ));
    }
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long A;
    A = input.front.to!long;
    input.popFront;

    long B;
    B = input.front.to!long;
    input.popFront;

    long Q;
    Q = input.front.to!long;
    input.popFront;

    long[] s = new long[](cast(size_t) (A));
    foreach (i; 0 .. cast(size_t) (A)) {
        s[i] = input.front.to!long;
        input.popFront;
    }

    long[] t = new long[](cast(size_t) (B));
    foreach (i; 0 .. cast(size_t) (B)) {
        t[i] = input.front.to!long;
        input.popFront;
    }

    long[] x = new long[](cast(size_t) (Q));
    foreach (i; 0 .. cast(size_t) (Q)) {
        x[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(A, B, Q, s, t, x);
    else
        solve(A, B, Q, s, t, x).writeln;
}


Measured memory_bytes: 6268
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long Count = 0l;
		int min = Integer.MAX_VALUE;
		for(int i = 0; i < N; i++) {
			int ch = sc.nextInt();
			if(ch <= min) {
				Count++;
				min = ch;
			}
		}
		System.out.println(Count);
	}
}

Measured memory_bytes: 63100
#include<bits/stdc++.h>
using namespace std;
#define M 1000000000
#define Smax 1000000000000000000
int main(){
  long S;cin>>S;
  if(S==Smax)cout<<"0 0 0 1000000000 1000000000 1000000000";
  else cout<<"0 0 1 1000000000 "<<S/M+1<<" "<<M-S%M;
}

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

int main() {
	long long int H, N;
	cin >> H >> N;
    while(N--) {
      int a;
      cin >> a;
      H -= a;
      if (H <=0) break;
    }
	if(H <=0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

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

  if(s=="ARC") cout<<"ABC";
  else cout<<"ARC";
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pii;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll mod = 1e9 + 7;
  ll res = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> freq(61, 0);
  for (ll a : A) {
    for (int j = 0; a > 0; j++, a /= 2) {
      freq[j] += (a % 2);
    }
  }
  for (ll a : A) {
    N--;
    ll base = 1;
    for (int j = 0; j <= 60; j++, a /= 2, base = base << 1) {
      base = base % mod;
      if (a % 2 == 1) {
        freq[j]--;
        res = (res + (base * (N - freq[j])) % mod) % mod;
      } else {
        res = (res + (base * freq[j]) % mod) % mod;
      }
    }
  }
  cout << res << endl;
  return 0;
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   int n,k; cin>>n>>k;
   vector<int> a(n);
   rep(i,0,n)cin>>a[i];
   rep(_,0,k){
      bool fin=1;
      rep(i,0,n)if(a[i]!=n){
         fin=0; break;
      }
      if(fin)break;
      vector<int> nxt(n,0);
      rep(i,0,n){
         int lb=max(0,i-a[i]);
         int rb=min(n,i+a[i]+1);
         nxt[lb]++; if(rb!=n)nxt[rb]--;
      }
      rep(i,0,n-1)nxt[i+1]+=nxt[i];
      swap(a,nxt);
   }
   rep(i,0,n)cout<<a[i]<<(i==n-1?'\n':' ');
   return 0;
}

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

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}


int main() {

int n;
cin >> n;
int ans = 0;
int v[n],c[n],cost[n];
rep(i,n)cin >> v[i];
rep(i,n)cin >> c[i];

rep(i,n)cost[i] = v[i]-c[i];

rep(i,n){
    if(cost[i]>0)ans += cost[i];
}

cout << ans << endl;
return 0;

}

Measured memory_bytes: 256