akhauriyash/Code-Regression huggingface dataset:
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;
constexpr int K[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
auto solve() {
  in<int> A;


  return K[A-1];
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for i in range(A+1):
    X_ = X
    X_ -= 500*i
    for j in range(B+1):
        X__ = X_
        X__ -= 100*j
        for k in range(C+1):
            X___ = X__
            X___ -= 50*k
            if X___ == 0:
                cnt += 1
print(cnt)

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

using ll = long long;

#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	ll n;
	cin>>n;

	ll ans = 0LL;

	for(ll d=1LL; d<=n; d++)
	{
		ll q = ll(n/d);

		// work out d*(1+2+...+q)

		ll cur = q;
		cur *= (q+1LL);
		cur /= 2LL;
		cur *= d;

		ans += cur;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    REP(o, n){
        string a, b; cin >> a >> b;
        int na = 0, nb = 0; 
        REP(i, a.size()){
            if(a[i] == 'm'){
                if(i != 0) na += 1000 * (a[i - 1] - '0');
                else na += 1000;
            } 
            if(a[i] == 'c'){
                if(i != 0 and (a[i - 1] != 'm')) na += 100 * (a[i - 1] - '0');
                else na += 100;
            }
            if(a[i] == 'x') {
                if(i != 0 and (a[i - 1] != 'm' and a[i - 1] != 'c')) na += 10 * (a[i - 1] - '0');
                else na += 10;
            }
            if(a[i] == 'i'){
                if(i != 0 and (a[i - 1] != 'm' and a[i - 1] != 'c' and a[i - 1] != 'x')) na += 1 * (a[i - 1] - '0');
                else na += 1;
            }
        }
        REP(i, b.size()){
            if(b[i] == 'm'){
                if(i != 0) nb += 1000 * (b[i - 1] - '0');
                else nb += 1000;
            } 
            if(b[i] == 'c'){
                if(i != 0 and (b[i - 1] != 'm')) nb += 100 * (b[i - 1] - '0');
                else nb += 100;
            }
            if(b[i] == 'x') {
                if(i != 0 and (b[i - 1] != 'm' and b[i - 1] != 'c')) nb += 10 * (b[i - 1] - '0');
                else nb += 10;
            }
            if(b[i] == 'i'){
                if(i != 0 and (b[i - 1] != 'm' and b[i - 1] != 'c' and b[i - 1] != 'x')) nb += 1 * (b[i - 1] - '0');
                else nb += 1;
            }
        }
        int nans = na + nb;
        string ans;
        if(nans / 1000 >= 2){
            ans += to_string(nans / 1000) + 'm';
            nans %= 1000;
        }
        else if(nans / 1000 == 1){
            ans += 'm';
            nans %= 1000;
        }

        if(nans / 100 >= 2){
            ans += to_string(nans / 100) + 'c';
            nans %= 100;
        }
        else if(nans / 100 == 1){
            ans += 'c';
            nans %= 100;
        }

        if(nans / 10 >= 2){
            ans += to_string(nans/ 10) + 'x';
            nans %= 10;
        }
        else if(nans / 10 == 1){
            ans += 'x';
            nans %= 10;
        }

        if(nans >= 2){
            ans += to_string(nans) + 'i';
        }
        else if(nans == 1) ans += 'i';

        cout << ans << endl;
    }
}


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

using namespace std;

char s[110];
int cnt1;

int main()
{
    scanf("%s",s+1);
    int ss=strlen(s+1);
    if(s[1]!='A') return puts("WA"),0;
    for(int i=3;i<=ss-1;i++) cnt1+=s[i]=='C';
    if(cnt1!=1) return puts("WA"),0;
    for(int i=1;i<=ss;i++) if(isupper(s[i])&&(s[i]!='C'&&s[i]!='A')) return puts("WA"),0;
    puts("AC");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
int mypow(int a,int b){
    if(b==0)return 1;
    if(b==1)return a;
    int t=mypow(a,b/2);
    if(b%2==0)return t*t;
    return t*t*a;
}
//library end
int h,w;
char c[60][60];
bool flag[60][60];
queue<P>que;
int d[60][60];
int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
int bfs(){
    P start=make_pair(1,1);
    d[1][1]=1;
    que.push(start);
    while(!que.empty()){
        P p=que.front();
        que.pop();
        if(p.F<=0||p.F>h||p.S<=0||p.S>w)continue;
        if(p.F==h&&p.S==w){
            return d[p.F][p.S];
        }
        rep(i,4){
            if(flag[p.F+dx[i]][p.S+dy[i]]==false&&c[p.F+dx[i]][p.S+dy[i]]=='.'){
                flag[p.F+dx[i]][p.S+dy[i]]=true;
                que.push(make_pair(p.F+dx[i],p.S+dy[i]));
                d[p.F+dx[i]][p.S+dy[i]]=d[p.F][p.S]+1;
            }
        }
    }
    return -1;
}
int white=0;
signed main(){
    cin>>h>>w;
    rep(i,h){
        rep(j,w){
            cin>>c[i+1][j+1];
            if(c[i+1][j+1]=='.')white++;
        }
    }
    int b=bfs();
    if(b==-1)cout<<-1<<endl;
    else cout<<white-b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%1000==0)
    {
        cout<<0<<endl;
        return 0;
    }
    int total =ceil( n/1000.0);
    cout<<(total*1000) - n<<endl;
}


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

using namespace std;

using i64 = long long;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);
  
  int N, W;
  cin >> N >> W;
  
  const i64 INF = 1e12;
  const int MAX = 1e5 + 5;
  vector<i64> dp(MAX, INF);
  dp[0] = 0; 

  int w, v; 
  for(int i = 1; i <= N; i++){
    cin >> w >> v;
    for(int j = MAX - 1; j >= v; j--){
      dp[j] = min(dp[j], dp[j - v] + w);
    }
  }
  int ans = 0;
  for(int i = 1; i < MAX; i++){
    if(dp[i] <= W) ans = max(ans, i);
  }
  
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

int main(void) {
    long int num, i, sum = 0, ave;
    
    scanf("%ld", &num);

    
    int va[num];
    
    for(i = 0; i < num; i++) {
        scanf("%d", &va[i]);
        
        sum += va[i];
    }
    
    ave = floor((double)sum / num);
    
    printf("%ld\n", ave);
    
    return(0);
}

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

void swp_i(int* N1,int* N2){
	int tmp=*N1;
	*N1=*N2;
	*N2=tmp;
}
void swp_c(char* S1,char* S2){
	char tmp[11];
	strcpy(tmp,S1);
	strcpy(S1,S2);
	strcpy(S2,tmp);
}
int main(){
	int sNum,lNum,lPat[10][10]={},lOn[10]={};
	cin>>sNum>>lNum;
	for(int i=0;i<lNum;i++){
		int K;
		cin>>K;
		for(int j=0;j<K;j++){
			int s;
			cin>>s;
			lPat[i][s-1]=1;
		}
	}
	for(int i=0;i<lNum;i++){
		cin>>lOn[i];
	}
	//cout<<endl;//
	int ans=0;
	for(int tmp_s=0;tmp_s<(1<<sNum);tmp_s++){
		//cout<<"< "<<tmp_s<<" >"<<endl;//
		for(int i=0;i<lNum;i++){
			//cout<<"lump "<<i<<endl;//
			int sum=0;
			for(int j=0;j<sNum;j++){
				//cout<<"switch "<<j<<endl;//
				//cout<<((tmp_s>>j)&1)<<" and "<<lPat[i][j]<<endl;//
				if((tmp_s>>j)&1 && lPat[i][j]){
					sum++;
				}
			}
			if((sum&1)!=lOn[i]){
				//cout<<"ONE OFF"<<endl;//
				goto NEXT;
			}else{
				//cout<<"this l is on"<<endl;//
			}
		}
		//cout<<"ALL ON"<<endl;//
		ans++;
		NEXT:;
		//cout<<endl;//
	}
	cout<<ans<<endl;
	return 0;
}


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

int n, M[MAX][MAX];

int prim() {
    int u, minv;
    int d[MAX], p[MAX], color[MAX];

    for ( int i = 0; i < n; i++ ) {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    d[0] = 0;

    while ( 1 ) {
        minv = INFTY;
        u = -1;
        for ( int i = 0; i < n; i++ ) {
            if ( minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if ( u == -1 ) break;
        color[u] = BLACK;
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                if (d[v] > M[u][v] ) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    for ( int i = 0; i < n; i++ ) {
        if ( p[i] != -1 ) sum += M[i][p[i]];
    }

    return sum;
}

int main() {
    cin >> n;

    for ( int i = 0; i < n; i++ ){
        for ( int j = 0; j < n; j++ ){
            int e; cin >> e;
            M[i][j] = (e == -1) ? INFTY : e;
        }
    }

    cout << prim() << endl;

    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;
bool possible = true;

vec p(1010,-1), x(1010);
mat G(1010,vec(0));

ll knapsack(ll maxi, vp &xs){
    vector<vector<bool> > dp(xs.size(),vector<bool>(5011,false));
    rep(i,xs.size()){
        if(i == 0){
            if(xs[0].fi < 5010) dp[0][xs[0].fi] = true;
            if(xs[0].se < 5010) dp[0][xs[0].se] = true;
        }else{
            rep(j,5011){
                ll one = xs[i].fi, two = xs[i].se;
                if(j - one >= 0){
                    dp[i][j] = dp[i-1][j - one];
                }
                if(j - two >= 0){
                    dp[i][j] = dp[i][j] || dp[i-1][j - two];
                }
            }
        }
    }
    rep(i,maxi + 1){
        if(dp[xs.size() - 1][maxi - i]) return maxi - i;
    }
    return -1;
}

P dfs(ll now){
    //cout<<now<<endl;
    vp xs(0);
    int id = 0, sum = 0;
    for(ll next : G[now]){
        xs.push_back(dfs(next));
        sum += xs[id].fi + xs[id].se;
        ++id;
    }
    if(xs.empty()){
        return mp(x[now], 0);
    }else{
        ll exc = knapsack(x[now], xs);
        if(exc == -1) {
            possible = false;
            return mp(0,0);
        }else{
            return mp(sum - exc, x[now]);
        }
    }
}

int main() {
    cin>>N;
    rep(i,N-1) {
        cin>>p[i+1];
        --p[i+1];
    }
    //cout<<'a'<<endl;
    rep(i,N) cin>>x[i];
    reps(i,1,N) G[p[i]].push_back(i);
    P pai = dfs(0);
    cout<<(possible ? "POSSIBLE" : "IMPOSSIBLE")<<endl;
}

Measured memory_bytes: 1024
S = input()
ans = 0
nd = 1
mod1 = 0
listmod = [0]*2019
for i in S[::-1]:
    mod1 = (int(i)*nd + mod1)%2019
    listmod[mod1] += 1
    nd = (nd*10)%2019
for i in range(2019):
    n = listmod[i]
    if(i == 0):
        if(n == 1):
            ans += 1
        elif(n >= 2):
            ans += ((n+1)*n)//2
    else:
        if(n > 1):
            ans += ((n-1)*n)//2
print(ans)

Measured memory_bytes: 9088
N = int(input())
p = list(map(float,input().split()))
dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1.0
for i in range(N):
    for j in range(N):
        dp[i+1][j+1] += dp[i][j]*p[i]
        dp[i+1][j] += dp[i][j]*(1-p[i])

ans = 0
for j in range((N//2)+1,N+1):
    ans += dp[N][j]
print(ans)

Measured memory_bytes: 252808
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[3005];
    int sum = 0;
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    printf("%d\n",sum-n);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

char change(char c, int n) {
    int d = c - 'A';
    d += n;
    d %= 26;
    return 'A' + d;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n;
    cin >> s;
    for (auto &c : s) {
        c = change(c, n);
    }
    cout << s << endl;

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(3*n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(n+v);
        G[n+u].push_back(2*n+v);
        G[2*n+u].push_back(v);
    }
    int s, t;
    cin >> s >> t;
    s--; t--;

    vector<int> res(3*n, INF);
    queue<int> que;
    res[s] = 0;
    que.push(s);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (auto nv : G[v]) {
            if (res[nv] == INF) {
                res[nv] = res[v] + 1;
                que.push(nv);
            }
        }
    }

    cout << (res[t] == INF ? -1 : res[t]/3) << endl;
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  int sum = A+B+C;
  int maxABC = max(A, max(B,C));
  int ans;
  if ((maxABC % 2) == (sum % 2)) ans = (maxABC*3 - sum)/2;
  else ans = ((maxABC+1)*3 - sum)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
	int a,b;
	cin >> a >> b;
	if(1<= a && a<=9 && 1<=b && b<=9){
		cout << a*b << endl;
	}
	else
	{
		cout << -1 << endl;
	}
	
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> A >> B >> C;
  A--;
  Out(B/C-A/C);
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  prllf("%d",x);
#define pl(x)  prllf("%lld",x);
#define pf(x)  prllf("%.10lf",x);
#define ps(x)  prllf("%s",x);
#define en() prllf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define mod 100000007
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}
ll prime[1000000];bool visprime[10000000];
void sieve(){ll k=0;for(ll i=2;i*i<=1000000;i++){for(ll j=i*i;j<=1000000;j+=i){visprime[j]=true;}}for(ll i=2;i<=1000000;i++){if(visprime[i]==false) prime[k++]=i;}}


int main()
{

    int n;
    cin>>n;
    int arr[n],brr[n],ex[n-1];
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int i=0;i<n;i++) cin>>brr[i];
    for(int i=0;i<n-1;i++) cin>>ex[i];

    int sat=0,ans=0,prev=-1;
    for(int i=0;i<n;i++)
    {
        int x=arr[i]-1;
        if(i!=0) prev=arr[i-1]-1;
        sat+=brr[x];
        if( prev!=-1 && prev+1==x) sat+=ex[x-1];


       // cout<<sat<<endl;
        ans+=sat;
        sat=0;
    }

    cout<<ans<<endl;





}
























Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

template <class T>
struct Node {
    T value;
    size_t parent, left, right;
    Node(): value(), parent(-1), left(-1), right(-1) {}
    Node(T v): value(v), parent(-1), left(-1), right(-1) {}
};

template <class T>
struct BinarySearchTree {
    vector<Node<T>> nodes;
    size_t root;
    BinarySearchTree(): root(-1) {}
    void insert(T v) {
        Node<T> z(v);
        nodes.push_back(z);

        size_t x=root, y=-1;
        while (~x) {
            y = x;
            if (v < nodes[x].value) {
                x = nodes[x].left;
            } else {
                x = nodes[x].right;
            }
        }

        nodes.back().parent = y;

        if (!~y) {
            root = 0;
        } else if (v < nodes[y].value) {
            nodes[y].left = nodes.size()-1;
        } else {
            nodes[y].right = nodes.size()-1;
        }
    }
    bool find(T v, size_t x=0) {
        size_t l=nodes[x].left;
        if (~l && nodes[x].value>v)
            if (find(v, l)) return true;

        size_t r=nodes[x].right;
        if (~r && nodes[x].value<v)
            if (find(v, r)) return true;

        return nodes[x].value == v;
    }
    template <class Functor>
    void walk_inorder(Functor F, size_t x=0) {
        if (!~x) return;

        walk_inorder(F, nodes[x].left);
        F(nodes[x]);
        walk_inorder(F, nodes[x].right);
    }
    template <class Functor>
    void walk_preorder(Functor F, size_t x=0) {
        if (!~x) return;

        F(nodes[x]);
        walk_preorder(F, nodes[x].left);
        walk_preorder(F, nodes[x].right);
    }
};

int main() {
    size_t n;
    scanf("%zu", &n);

    auto output=[](Node<int> &x)->void {
        printf(" %d", x.value);
    };

    BinarySearchTree<int> tree;
    for (size_t i=0; i<n; ++i) {
        char buf[1<<3];
        scanf("%s", buf);
        string instr(buf);

        if (instr == "insert") {
            int key;
            scanf("%d", &key);
            tree.insert(key);
        } else if (instr == "print") {
            tree.walk_inorder(output);
            printf("\n");
            tree.walk_preorder(output);
            printf("\n");
        } else if (instr == "find") {
            int key;
            scanf("%d", &key);
            printf("%s\n", tree.find(key)? "yes":"no");
        }
    }

    return 0;
}

Measured memory_bytes: 18928
#include <stdio.h>


int main(){
	int cont=0;
	long long h, a;
	scanf("%lld %lld", &h, &a);
	while(h>0 && h!=0){
		h= h-a;
		++cont;
	}

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

	return 0;
	
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> hotels(n);
    for (int i = 0; i < n; i++)cin >> hotels[i];

    int l;
    cin >> l;
    vector<vector<int>> move(n, vector<int>(25));
    for (int i = 0; i < n; i++) {
        move[i][0] = upper_bound(hotels.begin(), hotels.end(), hotels[i] + l) - hotels.begin() - 1;
    }
    for (int j = 1; j < 25; j++) {
        for (int i = 0; i < n; i++) {
            move[i][j] = move[move[i][j - 1]][j - 1];
        }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int from, to;
        cin >> from >> to;
        from--, to--;
        if (from > to)swap(from, to);

        int ok = 1000000;
        int ng = 0;
        while (ok - ng > 1) {
            int mid = (ok + ng) / 2;

            int now = from;
            for (int j = 0; j < 25; j++) {
                if ((1 << j) & mid)now = move[now][j];
            }

            if (now >= to)ok = mid;
            else ng = mid;
        }

        cout << ok << endl;
    }
    return 0;
}


Measured memory_bytes: 14464
N, S = map(int, input().split())
*A, = map(int, input().split())

ans = N+1

v = t = 0
for s in range(N):
    while t < N and v < S:
        v += A[t]
        t += 1
    if S <= v:
        ans = min(ans, t-s)
    v -= A[s]
print(ans if ans < N+1 else 0)



Measured memory_bytes: 16376
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    ll n;   cin >> n;
    ll *a = new ll[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a+n, greater<ll>());

    ll ans = a[0];
    int i = 1;
    if (n % 2 == 0) {
        for (; i <= n/2-1; i++)
            ans += 2*a[i];
    }
    else {
        for (; i <= (n-3)/2; i++)
            ans += 2*a[i];
        ans += a[(n-3)/2+1];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5188
n = int(input())
#文字列を一列ごとにリストに入れる
S = [input() for _ in range(n)]
alphabet_str = "abcdefghijklmnopqrstuvwxyz"
#alphbetの文字列をリスト化
alphabets = list(alphabet_str)

s_maps = []
for s in S:
#sはSの文字列の一つ一つ
#文字列sをリスト化    
    strs = list(s)
#辞書を作る
    m = {}
#各alphbetの初期値を0にする
    for alphabet in alphabets:
        m[alphabet] = 0
#文字列の中にあるalphabetがあれば、辞書のvalueに1を追加
    for _str in strs:
        m[_str] += 1
#辞書をリストに突っ込む      
    s_maps.append(m) 
#print(s_maps)
ans = ""
#alphabetリストからalphabetを取り出す
for alphabet in alphabets:
    min_num = 51
#リストから辞書を一つずつ取り出す    
    for s_map in s_maps:
#n個の辞書の中から最小のvalueを取り出す
        min_num = min(s_map[alphabet], min_num)
    for i in range(min_num):
        ans += alphabet
print(ans)
#taku689さんのコードを大いに参考

Measured memory_bytes: 3064
fun main (arg: Array<String>){
	var (A, B, C) = readLine()!!.split(" ").map(String::toInt)
	if(A == B){
		if(A == C){
			println("No")
		}else{
			println("Yes")
		}
	}else if(B == C){
		if(A == C){
			println("No")
		}else{
			println("Yes")
		}
	}else if(A == C){
		if(B == C){
			println("No")
		}else{
			println("Yes")
		}
	}else{
		println("No")
	}
}

Measured memory_bytes: 37776
import math
N = int(input())

ans = 0
mina = int((-1 + math.sqrt(1 + 4 * N)) / 2)
if (mina * 2 + 1) * (mina * 2 + 1) != 1 + 4 * N:
    mina += 1

for a in range(1, mina):
    if (N - a) % a == 0:
        ans += int((N - a) / a)
print(ans)






Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;
ll mod=998244353;

int main(){
    ll n;cin>>n;
    vector<ll> v(n),dist(1e5,0);
    for(int i=0;i<n;i++)cin>>v[i];
    if(v[0]!=0){cout<<0<<endl;return 0;}
    for(int i=1;i<n;i++){
        dist[v[i]]++;
    }
    ll ans=1;
    for(int i=1;i<n;i++){
        if(v[i]==0){cout<<0<<endl;return 0;}
        if(v[i]>=2)ans=(ans*dist[v[i]-1])%mod;
        ans%=mod;
    }
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 1792
mod = 10**9+7
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
def make_fact(n):#0~nの階乗を求める
    fact = [1]*(n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1]*i%mod
    return fact
fact = make_fact(N) #＠
def make_fact_inv(n):#0~nの階乗のmodに関する逆元を求める
    fact_inv = [1]*(n+1)
    fact_inv[n] = pow(fact[n], mod-2, mod)#フェルマーの小定理
    for i in range(n, 0, -1):
        fact_inv[i-1] = fact_inv[i]*i%mod
    return fact_inv
fact_inv = make_fact_inv(N)#＠
def comb(n, k):#nCk
    return fact[n]*fact_inv[k]*fact_inv[n-k]%mod
ans = 0
for i in range(N):
    if i+1>=K:
        ans+=A[i]*comb(i, K-1)
        ans%=mod
    if N-i>=K:
        ans-=A[i]*comb(N-i-1, K-1)
        ans%=mod
print(ans)




Measured memory_bytes: 63472
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int a, b;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> a >> b;
    if (a == b) 
        cout << a << endl;
    else if (a > b) 
        cout << a - 1 << endl;
    else 
        cout << a << endl;
    return 0;
}


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

int main() {
	map<char,int> mp;
	mp['I']=1;
	mp['V']=5;
	mp['X']=10;
	mp['L']=50;
	mp['C']=100;
	mp['D']=500;
	mp['M']=1000;
	string s;
	
	while(getline(cin,s)>0){
		int sum=0,before=0,tmp=0;
		for(int i=s.size()-1;i>=0;i--){
			if(before>mp[s[i]]){
				sum-=mp[s[i]];
			}else{
				sum+=mp[s[i]];
			}
			before=mp[s[i]];
		}
		cout<<sum<<endl;
	}return 0;
}

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

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

int main() {
  int N;
  cin >> N;
  vector<int> A;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
  }
  int d = A.at(0);
  for(int i=1;i<N;i++){
    d = gcd(d, A.at(i));
  }
  cout << d << endl;
  
  return 0;
}

Measured memory_bytes: 892
x, k, d = map(int, input().split())
x = abs(x)
ans = x-(x // d)*d
if k < (x // d):
    print(x - d * k)
    exit()
k -= (x // d)
if k % 2 == 0:
    print(ans)
else:
    print(abs(ans-d))


Measured memory_bytes: 9172
import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        int[] ary = new int[n];
        
        int min = 100;
        int max = -100;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            ary[i] = a;
            min = Math.min(min, a);
            max = Math.max(max, a);
        }
        
        long res = 4000000;
        for (int i = min; i <= max; i++) {
            long tmp = 0;
            for (int j = 0; j < n; j++) {
                tmp += Math.pow(ary[j]-i, 2);
            }
            res = Math.min(res, tmp);
        }
        
        System.out.println(res);
    }
}


Measured memory_bytes: 9556
##C
import math
a, b, h, m = map(int,input().split())
long = h * 30 + m * 0.5
short = m * 6
angle = abs(long - short)
if angle >= 180:
    angle2 = 360 - angle
else:
    angle2 = angle
x = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(angle2))
print(math.sqrt(x))


Measured memory_bytes: 9424
W = []
K = []
for i in range (10):
    W.append(int(input()))
for i in range (10):
    K.append(int(input()))
    
    W.sort(reverse = True)
    K.sort(reverse = True)
    point_W = sum(W[:3])
    point_K = sum(K[:3])

print(point_W, point_K)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 200005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
 vector<int> vi[maxii];
 vector<int>::iterator child;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];


int main()
{
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    int m,x,y;
    sc(m)
    for(int i=0;i<m;i++)
    {
        sc(x)
        sc(y)
        int p=arr[x];
        int sum1=sum-arr[x];
        sum1+=y;
        cout<<sum1<<endl;

    }

}






Measured memory_bytes: 8408
n, m, x = gets.split.map(&:to_i)

books = n.times.map {
  gets.split.map(&:to_i)
}

def solve(books, cost, remains)
  if books.empty?
    return remains.all? { |r| r <= 0 } ? cost : Float::INFINITY
  end

  next_books = books[1..-1]
  book = books[0]

  [
    solve(
      next_books.dup,
      cost + book[0],
      remains.zip(books[0][1..-1]).map { |r, b| r - b }
    ),
    solve(
      next_books.dup,
      cost,
      remains
    )
  ].min
end

result = solve(books, 0, Array.new(m, x))
result = -1 if result == Float::INFINITY
puts result


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

int main(){
int N;
  cin>>N;
  vector<long>A(N);
  for(int i=0; i<N; i++){
   cin>>A[i];
   A[i]-=i+1;} // 最初から(A[i]-i+1)の形にして
  
  sort(A.begin(), A.end());
  int b=A[(N-1)/2]; // 絶対値で計算されるため、bはsortしたA[i]の中の中央値に近い値が望ましい
  
  long ans=0;
  for(int i=0; i<N; i++){
   ans+=abs(A[i]-b);
  }
  
  cout<<ans;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int dp[100010];

int main(void)
{
    int platform_counts;
    vector<int> heights;
    int jump_range;

    cin >> platform_counts >> jump_range;

    for(int i = 0; i < platform_counts; i++){
        int h;
        cin >> h;
        heights.push_back(h);
    }

    dp[0] = 0;

    for(int i = 1; i < platform_counts; i++){
        vector<int> costs;
        for(int j = i - 1; j >= i - jump_range; j--){
            costs.push_back(dp[j] + abs(heights[j] - heights[i]));

                if(j == 0){
                    break;
                }
            }
            dp[i] = *min_element(costs.begin(), costs.end());
    }

    cout << dp[platform_counts - 1] << endl;

    return 0;
}

Measured memory_bytes: 1144
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int n;
void dfs(string s, char c, int len) {
  if(len == n) {
    cout << s << endl;
    return;
  }
  rep(i, c - 'a' + 2) {
    char nc = 'a' + i;
    dfs(s + nc, max(c, nc), len + 1);
  }
  return;
}
int main() {
  cin >> n;
  dfs("a", 'a', 1);
  return 0;
}

Measured memory_bytes: 1536
/*
 *  Author : Jun_SH
 *  Solution for ABC 146 F
 */
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
    int f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
const int maxn=1e5+10;
vector<int>ans;
main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    string s;
    cin>>n>>k>>s;
    int pos=n;
    int f=1;
    while(pos&&f){
        int l=max(0ll,pos-k);
        int tmp=0;
        if(l==0){
            ans.emplace_back(pos);
            break;
        }
        while(s[l+tmp]=='1'&&(l+tmp)!=pos){
            tmp++;
        }
        if(l+tmp==pos)f=0;
        else {
            ans.emplace_back(pos-l-tmp);
            pos=l+tmp;
        }
    }
    if(f){
        int len=ans.size();
        for(int i=len-1;i>=0;--i)
            cout<<ans[i]<<" ";
        cout<<endl;
    }
    else cout<<(-1)<<endl;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll a,b,c;
  cin >> a >> b >> c;
  set<ll> s;
  s.insert(a);
  s.insert(b);
  s.insert(c);

  cout << s.size() << endl;
}


Measured memory_bytes: 256
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        if isCLKWISE(phU) : continue
        while(True):
            del phU[-2]
            if len(phU) == 2 : break
            else :
                if isCLKWISE(phU) : break

    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        if isCLKWISE(phL) : continue
        while(True):
            del phL[-2]
            if len(phL) == 2 : break
            else :
                if isCLKWISE(phL) : break

                
                
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1])

Measured memory_bytes: 33824
#include<bits/stdc++.h>
using namespace std;
char s[30];
int cnt[255];
int main()
{
	scanf("%s",s);
	int n=strlen(s);
	for(int i=0;i<n;i++)cnt[s[i]]++;
	if(n<26)
		for(int i='a';i<='z';i++)
			if(!cnt[i]){printf("%s%c\n",s,i);return 0;}
	if(!strcmp(s,"zyxwvutsrqponmlkjihgfedcba")){puts("-1");return 0;}
	for(int i=24;i>=0;i--)
		if(s[i]<s[i+1])
		{
			for(int j=0;j<i;j++)putchar(s[j]);
			for(int j=i;j<n;j++)cnt[s[j]]--;
			for(int j=s[i]+1;j<='z';j++)
				if(!cnt[j]){printf("%c\n",j);return 0;}
			return 0;
		}
}

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

int main()
{
    string S;
    cin >> S;
    int res = numeric_limits<int>::max();
    for(int i=0; i<=S.size()-3; i++){
        auto v = stoi(S.substr(i, 3));
        res = min(res, abs(v-753));
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

n =inp[0]
a = [0]+inp
t = na(n+1,0)
ft = na(n+1,false)
ans = []
((n/2+1)..n).each do |i|
  ft[i] = true
  if(1 == a[i])
    t[i] = 1
    ans.push(i)
  end
end
(1..(n/2)).reverse_each do |i|
  d = i*(n/i)
  c = 0
  while d > 0
    c += t[d]
    if(ft[d])
      d -= i
      next
    end
    ft[d] = true
    if(c % 2 != a[i])
      t[i] = 1
      ans.push(i)
    end
    d -= i
  end
end
puts ans.size
puts ans.join(" ") if(ans.size > 0)

Measured memory_bytes: 26316
#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 a,b,k;
    cin>>a>>b>>k;
    int cnt=0,ans=0;
    for(int i=100; i>=1; --i){
        if(a%i==0&&b%i==0){
            cnt++;
            ans=i;
        }
        if(cnt==k){
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,srt,end) for (long long i = (srt); i<(long long)(end); i++)
typedef long long ll;
ll A,B;
int main(){
    cin>>A>>B;
    ll ans=0;
    ll m8 =(A+(0.079))/(0.08);
    ll m10=(B+(0.099))/(0.1);
    ans=max(m8,m10);
    //cout<<m8<<" "<<m10<<endl;
    if((ans*8/100)!=A||(ans*1/10)!=B)cout<<"-1";
    else cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static long M = 1_000_000_007;
	private static List<Integer>[] g;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		g = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			g[i] = new ArrayList<>();
		}

		for (int i = 0; i < n - 1; i++) {
			int x = sc.nextInt() - 1;
			int y = sc.nextInt() - 1;
			g[x].add(y);
			g[y].add(x);
		}

		long answer = (k * dfs(0, k, 0 - 1)) % M;
		System.out.println(answer);
	}


	private static long dfs(int v, int k, int from) {
		int color = (from == -1) ? k - 1 : k - 2;
		if (k < g[v].size()) return 0;
		long a = 1;
		for (int x : g[v]) {
			if (x == from) continue;
			a = (a * color) % M;
			color--;
		}

		for (int x : g[v]) {
			if (x == from) continue;
			a = (a * dfs(x, k, v)) % M;
		}

		return a;
	}
}


Measured memory_bytes: 113440
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  ll n,m;
  cin >> n >> m;
  ll buf = 0;
  map<ll,ll> acc;
  acc.emplace(0,1);
  rep(i,n){
    ll b;
    cin >> b;
    buf = (buf + b) % m;
    acc[buf] += 1;
  }
  ll ans = 0;
  for(auto it = acc.begin(); it != acc.end(); it++){
    ll buf = it -> second;
    //cout << it -> first <<" "<<buf << endl;
    ans += buf * (buf-1) / 2;
  }
  cout << ans << endl;
}



Measured memory_bytes: 4224
#include <iostream>
using namespace std;
int main(void)
{
	double date[41][2];
	int num=0;
	while(cin >> date[num][0] >> date[num][1]){
		num++;
	}
	double judge[5] = {0,0.2,0.6,1.1,100};
	int out[4][2] = {0};
	for(int i=0;i<num;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<4;k++){
				if(judge[k] <= date[i][j] && date[i][j] < judge[k+1]){
					out[k][j]++;
					break;
				}
			}
		}
	}
		for(int i=3; i>=0; i--){
			cout << out[i][0] << " " << out[i][1] << endl;
		}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


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


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

int main(){
  int N,ans=0;
  cin >> N;
  string S[N];
  for(int i=0; i<N; i++) cin >> S[i];
  sort(S,S+N);
  for(int i=0; i<N; i++){
    while(S[i]==S[i+1]) i++;
    ans++;
  }
  cout  << ans << endl;
  return 0;
}


Measured memory_bytes: 9884
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> ii;
 
int main(){
  int n,m,x=0;
  cin>>n>>m;
  vector<ii> a(n);
  for(int i=0;i<n;i++)
    cin>>a[i].first>>a[i].second;
  sort(a.begin(),a.end());
  int i=0;
  long long y=0;
  while(x<m) {
    if(a[i].second>0) y+=a[i].first, a[i].second--, x++;
    else i++;
  }
  cout<<y<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main() {
  int n, d;
  scanf("%d %d", &n, &d);
  int cansee = d * 2 + 1;
  int ans = 0;
  while(n > 0) {
    n -= cansee;
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
#define nl '\n'
#define eb emplace_back
#define f(i,start,n) for(int i=start; i<=n; i++)
#define pi 3.1415926535
#define mod 1000000000+7
#define MAX 100000+1
#define t int t; cin >> t; while(t--)

int mark[200001];
int max_ = 0;

int main()
{
    FASTIO;
    //t
    {
        int a,b; cin >> a >> b;
        cout << a*b << endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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 (b<a) { a=b; return 1; } return 0; }

int main() {
  int N; cin >> N;
  map<int, int> map;
  rep (i, N) map[i] = 0;
  vector<int> a(N);
  reps (i, N) {
    cin >> a[i];
    --a[i];
    map[a[i]] ++;
  }
  rep (i, N)
    cout << map[i] << endl;
  return 0;
}


Measured memory_bytes: 13556
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(ll i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

//********************************template END****************************************//

void solve(void){

	int N;
	cin >> N;
	vecll xs(N), acc(N+1);
	rep(N, i)
	{
		cin >> xs[i];
		acc[i+1] = xs[i];
	}

	rep(N, i)
	{
		acc[i+1] += acc[i];
	}

	ll ans = INFL;

	Rep(2, N-2, m)
	{
		ll L = acc[m], R = acc[N] - acc[m];
		//cout << L << ' ' << R << endl;
		auto l = lower_bound(acc.begin(), acc.begin()+m, L/2);
		auto r = lower_bound(acc.begin()+m, acc.end(), L+R/2);
		//cout << *l << ' ' << *r << endl;
		rep(4, i)
		{
			auto ll = l - (i & 1), rr = r - i / 2;
			ans = min(max({*ll, L-*ll, *rr-L, acc[N]-*rr}) - min({*ll, L-*ll, *rr-L, acc[N]-*rr}), ans);
		}
	}

	cout << ans << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_S = 100100;

int main()
{
    int n; cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];

    ll dp[n];
    rep(i,n) dp[i] = 0;
    dp[0] = 1000;

    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            ll res = (dp[j]/a[j])*a[i] + dp[j]%a[j];
            dp[i] = max(dp[i], res);
        }
        dp[i] = max(dp[i], dp[i-1]);
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 3600