akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

	ll rsl = 0;
	for(int mask = 0; mask < 1 << (S.size() - 1); mask++) {
		ll tmp = (ll)(S[0] - '0');
		for(int i = 0; i < S.size() - 1; i++) {
			if(mask & 1 << i) {
				rsl += tmp;
				tmp = (ll)(S[i + 1] - '0');
			} else {
				tmp *= 10;
				tmp += (ll)(S[i + 1] - '0');
			}
		}
		rsl += tmp;
	}
	cout << rsl << endl;
}


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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	rep(i,7)
	{
		int a,b;
		cin >> a >> b;

		cout << a-b << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;
int n;
unsigned long long a,m;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>m;
		a+=m-1;
	}
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <utility>
#include <array>
#include <algorithm>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?n=0,false:n=in<T>(c),true;}
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

using A = array<int, 100>;
using I = A::iterator;

void rec(int n, I b, I i) {
	if (!n) {
		out(*b);
		for_each(b + 1, i + 1, [&](int i){out(" ", i);});
		outl();
		return;
	}
	for (int j = min(n, *i ? *i++ : n); j > 0; j--) {
		*i = j;
		rec(n - j, b, i);
	}
}

int main() {
	for (int n; (n = in());) {
		A a {};
		rec(n, begin(a), begin(a));
	}
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b)
#define mins(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    ll n;cin>>n;

    if(n%2==1){
        cout<<0<<"\n";
        return 0;
    }

    n/=2;
    ll ans=0;
    while(n!=0){
        ans+=n/5;
        n/=5;
    }
    
    cout<<ans<<"\n";

    return 0;

}


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

long long factorial(long long n){
    long long res=1;
    for(long long i=1; i<n+1; i++){
        res *= i;
    }
    return res;
}

int main(void)
{
    long long m, n;
    cin >> n >> m;
    long long res;
    cout << n*(n-1)/2+m*(m-1)/2 << endl;
}

Measured memory_bytes: 256
N=int(input())
S=list(input())
rc,bc,gc=[0]*N,[0]*N,[0]*N
if S[0]=="R":
  rc[0]+=1
elif S[0]=="B":
  bc[0]+=1
if S[0]=="G":
  gc[0]+=1
for i in range(1,N):
  if S[i]=="R":
    rc[i]=rc[i-1]+1
    bc[i]=bc[i-1]
    gc[i]=gc[i-1]
  elif S[i]=="B":
    bc[i]=bc[i-1]+1
    gc[i]=gc[i-1]
    rc[i]=rc[i-1]
  elif S[i]=="G":
    gc[i]=gc[i-1]+1    
    rc[i]=rc[i-1]
    bc[i]=bc[i-1]

ans=0
for i in range(N-2):
  for j in range(i+1,N-1):
    if S[i]==S[j]:
      pass
    else:
      if [S[i],S[j]]==["R","B"] or [S[i],S[j]]==["B","R"]:
        ans+=gc[-1]-gc[j]
        if 2*j-i<N:
          if S[2*j-i]=="G":
            ans-=1
      elif [S[i],S[j]]==["B","G"] or [S[i],S[j]]==["G","B"]:
        ans+=rc[-1]-rc[j]
        if 2*j-i<N:
          if S[2*j-i]=="R":
            ans-=1
      elif [S[i],S[j]]==["G","R"] or [S[i],S[j]]==["R","G"]:
        ans+=bc[-1]-bc[j]
        if 2*j-i<N:
          if S[2*j-i]=="B":
            ans-=1
            
print(ans)


Measured memory_bytes: 68976
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;

int a[200010];
int b[200010];
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    set<ll> st;
    REP(i, n){
        ll a, b; cin >> a >> b;
        if(a==1){
            if(st.find(b)!=st.end()) cout << 1 << endl;
            else cout << 0 << endl;
        }else if(a==0){
            st.insert(b);
            cout << st.size() << endl;
        }else if(a==2){
            st.erase(b);
        }else{
            ll c; cin >> c;
            for(auto itr=st.lower_bound(b); itr!=st.upper_bound(c); ++itr) cout << *itr << endl;
        }
    }
	return 0;
}


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

int main() {

	long long n,i,j,k,sum=0,count=0,ans=0,x,c,d,mx=0,mn=1000000;
	cin>>n;
    long long a[n];
    for(i=0;i<n;i++)
    {cin>>a[i];
    }
    sort(a,a+n);
    
        cout<<a[n/2]-a[n/2-1];
    
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    string s,a,b,p;
    long long n,t,i,q;
    cin>>s;
    n=s.size();
    t=(n-1)/2;
    q=(n+3)/2;
    p=s;
    reverse(s.begin(),s.end());
    if(p==s)
    {
       a=s.substr(0,t);
       b=s.substr(q-1,n-1);

       string m=a;
       reverse(a.begin(),a.end());
       string h=b;
       reverse(b.begin(),b.end());
       if(m==a && b==h)
        cout<<"Yes"<<endl;
       else
        cout<<"No"<<endl;


    }
    else cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include <stdio.h> 

int main() 
{ 
  long int n, m; 
  scanf("%ld %ld", &n, &m); 
  if(n >= 10) 
    printf("%ld\n", m); 
  else 
    printf("%ld\n", m + (100*(10-n))); 
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define NL << endl

using namespace std;
using ll = long long;

int a[10] = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4 };
int b[10] = { 1, 1, 2, 2, 3, 3, 4, 4, 0, 0 };
int c[10] = { 2, 3, 3, 4, 4, 0, 0, 1, 1, 2 };


int main() {

	ll x[5] = { 0 };

	int n;
	cin >> n;
	REP(i, n) {
		string s;
		cin >> s;
		switch (s[0]) {
		case 'M':
			x[0]++; break;
		case 'A':
			x[1]++; break;
		case 'R':
			x[2]++; break;
		case 'C':
			x[3]++; break;
		case 'H':
			x[4]++;

		}
	}

	ll ans = 0;
	REP(i, 10) {
		ans += x[a[i]] * x[b[i]] * x[c[i]];
	}


	cout << ans NL;


	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int adj[101][101];

int main(){
	int i,j,n,u,k,v;	scanf("%d",&n);

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

		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++){
			scanf("%d",&v);
			adj[u][v]=1;
		}
	}

	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(j>1)printf(" ");
			printf("%d",adj[i][j]);
		}
		printf("\n");
	}


	return 0;
}



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

using namespace std;

struct CWW{CWW(){ios::sync_with_stdio(false);cin.tie(0);}}cww;

typedef long long LL;
const LL MOD=1e9+7;
typedef vector<int> V;
typedef vector<V> VV;


int main(){
    int N,K;
    cin>>N>>K;
    vector<int> D(K);
    for(auto&it:D)cin>>it;
    for(;;N++){
	string s=to_string(N);
	if([&](){
		for(auto&a:s)for(auto &b:D)if(a-'0'==b)return false;
		return true;
	}()){
	    cout<<N<<endl;
	    return 0;
	    }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;

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

string s;
string t = "AIZUNYAN", u = "AIDUNYAN";
vi w(26, 0);

bool calc(int n){
	vi v(26, 0);
	for(int i = 0; i < 8 && i + n < s.size(); i++) v[s[i + n]-'A']++;
	for(int i = 0; i < 26; i++){
		if(v[i] != w[i]) return false;; 
	}
	for(int i = 0; i < 8; i++){
		s[i + n] = t[i];
	}
	return true;
}


int main(){
	for(int i = 0; i < u.size(); i++) w[u[i]-'A']++;
	cin>>s;
	for(int i = 0; i < s.size(); i++) {
		bool f = calc(i);
		if(f) i += 7;
	}
	cout<<s<<endl;
}

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

using namespace std;

#define io freopen("test.txt", "r", stdin);
#define fast ios_base::sync_with_stdio(0);cin.tie(0);


#define ull unsigned long long int
#define lli long long int
#define li long int
#define ld long double

#define cout(x) cout<<x<<" "
#define coutn(x) cout<<x<<endl
#define newline cout<<endl

#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define ar array

#define pii pair<int,int>
#define pll pair<lli,lli>
#define pps pair<pair<int,int>, string>

const int MOD=1000000007;
const lli INF=1e18;
const int MX=100001;
const int N=1000000;


int main(){
    fast
    
    string s,t;
    cin>>s>>t;

    int n=s.size(),l=t.size();

    int mx=-1,c=0;
    for(int i=0;i<=n-l;i++){
        if(n-i<l) continue;
        for(int j=0;j<l;j++){
            if(s[j+i]==t[j]) c++;
        }
        mx=max(mx,c);
        c=0;
        //cout<<mx<<"\n";
    }

    mx=max(mx,c);

    cout<<l-mx<<"\n";
    
    return 0;
}

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

int n;
vector<vector<int>> g;

vector<int> bfs(int to, vector<int> dist){
  queue<pair<int,int>> que;
  int c = 0;
  que.emplace(to,c);

  while(!que.empty()){
    to = que.front().first;
    c = que.front().second;
    que.pop();
    dist[to] = c;

    for(auto v:g[to]){
      if(dist[v]==-1){
        que.emplace(v,c+1);
      }
    }   
  }
  return dist;
}

int main(){
  cin >> n;
  g.assign(n,vector<int>());

  for (int i = 0; i < n-1; i++)
  {
    int a,b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> from1(n,-1);
  vector<int> fromn(n,-1);

  from1 = bfs(0,from1);
  fromn = bfs(n-1,fromn);

  int fenn = 0;
  int sunu = 0;
  for (int i = 1; i < n-1; i++)
  {
    if(from1[i]<=fromn[i]) fenn++;
    else sunu++;
  }
  if(fenn>sunu) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define maxn (int)3010
int n, tab[maxn];
long long int dp[maxn][maxn];
int main()
{
	scanf("%d", &n);
	for (int i=1; i<n; i++)
	{
		char x;
		scanf(" %c", &x);
		if (x=='>') tab[i]=1;
		else tab[i]=2;
	}
	dp[1][1]=1;
	for (int i=1; i<=n; i++)
	{
		for (int o=1; o<n; o++) dp[i][o+1]=(dp[i][o+1]+dp[i][o])%M;
		if (i<n)
		{
			for (int o=1; o<=i; o++)
			{
				// <
				if(tab[i]==2) dp[i+1][o+1]=(dp[i+1][o+1]+dp[i][o])%M;
				// >
				if(tab[i]==1) dp[i+1][o]=(dp[i+1][o]+dp[i][n]-dp[i][o-1]+2*M)%M; //+M %m
			}
		}
	}
	printf("%lld\n", dp[n][n]);
}


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

/* -------- <templates end> -------- */


void solve() {
  int n; cin >> n;
  cout << (n - 2) * 180 << endl;
}


/* -------- <programs end> -------- */


signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


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

int main(){
    int n, i, h;
    cin >> n;
    int mx = -1, c = 0;
    for(i = 0; i < n; i++){
        cin >> h;
        if(mx <= h){
            c++;
            mx = h;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int ans = 0;
	rep(i,s.size() - 1){
		if(s.at(i) != s.at(i + 1)) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream> 
using namespace std;
#define ll long long
int main() {
  ll n; cin >> n;
  ll i=1;
  string s;
  while ( n ) {
    ll val = 26;
    ll idx = n%val;
    s.push_back('a' + (idx +25)%26);
    if (idx == 0) n-=26;
    else n -= idx;
    n/=val;
    i++;
  }
  reverse(s.begin(),s.end());
  cout << s << endl;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a > c) {
    swap(a, c);
    swap(b, d);
  }
  if (b > c) {
    if (b > d) {
      cout << d - c << endl;
    } else {
      cout << b - c << endl;
    }
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int n,a[220000],cnt=0,b=1;
signed main()
{
	cin>>n;
	if(n%2==1){
		cout<<0<<endl;
		return 0;
	}else{
		rep(i,25){
			b*=5;
			cnt+=n/(b*2);
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 384
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;

public class Test
{
    public static void Main()
    {
        Console.ReadLine();
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int res = 0;
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] == i + 1)
            {
                i++;
                res++;
            }
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 20064
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

int n, k;

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

	cin >> n >> k;

	cout << max(n * k, max(n + k, n - k)) << endl;


	return 0;
}


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

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

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main()
{
    int N;
    cin >> N;
    cout << N * N * N << endl;
}

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


int main() {
  ll n; cin>>n;
  vector<ll> v(n);
  rep(i,n){cin>>v[i];}
  ll sum=0;
  rep(i,n){
    ll a; cin>>a;            
    v[i]-=a;           
    sum+=v[i];
  }    
  sort(v.begin(),v.end());
  //cout<<sum<<endl;
  ll ans=0;
  if(sum<0){ans=-1;}
  else{
    ll minus=0;
    int i=0;
    while(true){
      if(v[i]<0){minus+=v[i];i++;}
      else{break;}
    }
    //cout<<i;
    int j=n-1;
    while(minus<0){
      if(v[j]>0){minus+=v[j];j--;}
      else{break;}
    }
    //cout<<j;
    ans=i+n-j-1;
  }
  cout<<ans;
}
  

Measured memory_bytes: 4028
from math import log10
x = int(input())

if x % 7 == 0:
    L = (x*9)/7
else:
    L = 9*x

if L % 2 == 0 or L % 5 == 0:
    print(-1)
    exit(0)

n = 1
amari = 1
while n < 9000000:
    amari = (amari*10) % L
    if amari == 1:
        print(n)
        exit(0)
    else:
        n += 1
print(-1)

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
using ll = long long int;

using namespace std;

struct edge {
  int to, cost;
};
vector<int> color;
vector<vector<edge>> E;
void dfs(int v, ll dist) {
  if(dist % 2 == 0) color[v] = 0;
  else color[v] = 1;
  REP(i, E[v].size()) {
    if(color[E[v][i].to] == -1) {
      dfs(E[v][i].to, dist+E[v][i].cost);
    }
  }
}

int main() {
  int N;
  cin >> N;
  color.resize(N);
  E.resize(N);
  REP(i, N) color[i] = -1;
  REP(i, N-1) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    E[u].push_back(edge({v, w}));
    E[v].push_back(edge({u, w}));
  }
  dfs(0, 0);
  REP(i, N) {
    cout << color[i] << endl;
  }
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n;
  cin >> n;
 
  map<string,long long> mp;
 
  string l;
  long long ans=0;
  for(int i =0; i < n; i++){
    cin >> l;
    sort(l.begin(),l.end());
    ans+=mp[l];
    mp[l]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11136
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
n=len(arr)
l=0
r=n-1
ans=1
if k%2==1:
    ans=arr[0]
    l=1
m=10**9+7
if ans<0:
    ans=1
    for i in range(k):
        ans*=arr[i]
        ans%=m
    print(ans)
    quit()
for i in range(k//2):
    po=arr[l]*arr[l+1]
    ne=arr[r]*arr[r-1]
    if po>=ne:
        l+=2
        ans*=po
        ans%=m
    else:
        r-=2
        ans*=ne
        ans%=m
print(ans)



Measured memory_bytes: 104704
def main():
    n, x = map(int, input().split())
    a = [int(x) for x in input().split()]
    answer = 0
    for i in range(1, n):
        if x < a[i - 1] + a[i]:
            answer += a[i - 1] + a[i] - x
            a[i] -= min(a[i], a[i] + a[i - 1] - x)
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 14132
hw_list = list(map(int, input().split()))
h = hw_list[0]
w = hw_list[1]
row_list = ['.'*(w+2)]

def impossible_check(area, x, y):
    impossible = True
    if area[y-1][x] == '#':
        impossible = False
    if area[y][x-1] == '#':
        impossible = False
    if area[y][x+1] == '#':
        impossible = False
    if area[y+1][x] == '#':
        impossible = False
    return impossible

for i in range(h):
    row_list.append('.'+ input()+ '.')
row_list.append('.'*(w+2))

for y in range(1, h+1):
    for x in range(1, w+1):
        if row_list[y][x] == '#' and impossible_check(row_list, x, y):
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000009;
#define PI 3.14159265
int dp[100005][3];
int main()
{
    fastio;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        if(i==0)
        {
            dp[i][0] = a;
            dp[i][1] = b;
            dp[i][2] = c;
        }
        else
        {
            dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a;
            dp[i][1] = max(dp[i-1][2],dp[i-1][0]) + b;
            dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c;
        }
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
    return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;


class Main {

	public static void main(String[] args) {   

		Scanner scanner = new Scanner(System.in);

		double x1 = scanner.nextDouble();
		double y1 = scanner.nextDouble();
		double x2 = scanner.nextDouble();
		double y2 = scanner.nextDouble();

		double P1 =Math.abs(Math.pow(x2-x1, 2));//各座標の距離の２乗の絶対値を求める
		double P2 =Math.abs(Math.pow(y2-y1, 2));
	 System.out.println(Math.sqrt(P1+P2));//合計の平方根を求める

		scanner.close();
	}
}



Measured memory_bytes: 27740
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
using namespace std;
const int N=(1<<16)+100,mod=1e9+7;
int n,m,a[N],f[2][N],fac[N],inv[N],ans;
int ksm(int x,int y){
	int s=1;
	for (;y;y>>=1,x=(ll)x*x%mod) if (y&1) s=(ll)s*x%mod;
	return s;
}
void init(int n){
	fac[0]=1;
	rep (i,1,n) fac[i]=(ll)fac[i-1]*i%mod;
	inv[n]=ksm(fac[n],mod-2);
	for (int i=n-1;~i;i--) inv[i]=(ll)inv[i+1]*(i+1)%mod;
}
int C(int n,int m){
	if (n<m) return 0;
	return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;
}
void upd(int &x,int y){x+=y; x-=x>=mod?mod:0;}
int main(){
	scanf("%d%d",&n,&m); init(N-1);
	rep (i,1,m) scanf("%d",&a[i]); reverse(a+1,a+1+m);
	int now,tmp; f[now=0][0]=1;
	rep (i,1,m){
		now^=1; memset(f[now],0,sizeof(f[now]));
		rep (j,0,(1<<n)-1)
			if (tmp=f[now^1][j]){
				upd(f[now][j],tmp);
				rep (k,0,n-1) if (!(j>>k&1))
					upd(f[now][j|1<<k],(ll)C((1<<n)-j-a[i],(1<<k)-1)*fac[1<<k]%mod*tmp%mod);
			}
	}
	rep (i,0,(1<<n)-1){
		int tmp=(ll)f[now][i]*fac[(1<<n)-1-i]%mod;
		if (__builtin_popcount(i)&1) upd(ans,mod-tmp); else upd(ans,tmp);
	}
	printf("%lld\n",(ll)ans*(1<<n)%mod);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

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

  int min_two = 10000;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;

    int two = 0;
    while (a % 2 == 0) {
      two++;
      a /= 2;
    }
    if (two < min_two)
      min_two = two;
  }

  cout << min_two << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int number;
    int i;
    int num[100];
    int block = 0;
 
    do{
      scanf("%d", &number);
    }while(number < 1 || number > 100);
  
    for(i = 0; i < number; i++){
       do{
       scanf("%d", &num[i]); 
       }while(num[i] < 1 || num[i] > 1000);
    }
  
    for(i = 0; i < number; i++){ 
       if(num[i] % 2 == 0){
         if(num[i] % 3 != 0 && num[i] % 5 != 0){ 
           block=1;
         }
       } 
    }
    if(block==0) {
      printf("APPROVED");
    }else{
      printf("DENIED");
    }
    return 0;
}

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

int x[110];

int main(){
  int n; cin >> n;
  int max = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i+1];
    max += x[i+1];
  }
  int m; cin >> m;
  for (int i = 0; i < m; i++) {
    int p, q; cin >> p >> q;
    cout << max + (q - x[p]) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import Counter
import bisect
from collections import defaultdict
import itertools
def main():
    N, X, M = MI()
    circle = [X]
    ans = 0
    i = 1
    num_list = [0] * (M + 1)
    a = X
    while num_list[a] == 0:
        num_list[a] = i
        a = pow(a, 2, M)
        circle.append(a)
        i += 1
    b = num_list[a]
    del circle[-1]
    sta = circle[:b - 1]
    v = len(sta)
    w = sum(sta)
    circle = circle[b - 1:]
    x = len(circle)
    y = sum(circle)
    if N <= v:
        ans = sum(sta[:N + 1])
        print(ans)
        exit()
    else:
        ans = w
        p, q = divmod(N - v, x)
        ans += y * p
        if q != 0:
            for i in range(q):
                ans += circle[i]

        print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 72164
# include <cstdio>
# include <iostream>
# include <cstring>
# include <cmath>
# include <algorithm>
# include <string>
# define ll long long
# define R register int
 
using namespace std;
 
const int maxn=1003;
int n,m,f=-1;
ll x[maxn],y[maxn];
ll d[35],len;
 
inline ll ab (ll x) { if(x<0) return -x; return x; }
 
inline void solve (ll x,ll y)
{
	for (R i=1;i<=m-((f&1)^1);++i)
	{
		if(ab(x)>ab(y))
		{
			if(x>0) putchar('R'),x-=d[i];
			else putchar('L'),x+=d[i];
		}
		else
		{
			if(y>0) putchar('U'),y-=d[i];
			else putchar('D'),y+=d[i];
		}
	}
	if(f%2==0) putchar('L');
	putchar('\n');
}
 
int main()
{
	scanf("%d",&n);
	for (R i=1;i<=n;++i)
	{
		scanf("%lld%lld",&x[i],&y[i]);
		len=ab(x[i])+ab(y[i]);
		if(f==-1) f=len%2;
		if(f%2!=len%2)
		{
			printf("-1");
			return 0;
		}
	}
	for (R i=30;i>=0;--i) d[++m]=(1LL<<i);
	if(f%2==0) d[++m]=1;
	printf("%d\n",m);
	for (R i=1;i<=m;++i)
    {
    	printf("%lld",d[i]);
		if(i==m) printf("\n");
		else printf(" ");
	}
	for (R i=1;i<=n;++i)
		solve(x[i]+((f&1)^1),y[i]);
	return 0;
}

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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int n,m,a[50],b[50],c[50],d[50],ans[50];

main() {
    cin >> n >> m;
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,m) cin >> c[i] >> d[i];
    rep(i,n) {
        int cnt=1000000000,hoge;
        rep(j,m) {
            int z=cnt;
            cnt = min(cnt,abs(a[i]-c[j])+abs(b[i]-d[j]));
            if (cnt != z) hoge = j+1;
        }
        ans[i] = hoge;
    }
    rep(i,n) ct(ans[i])
}


Measured memory_bytes: 256
"""
ナップサック問題
"""
N,W = map(int, input().split())
dp = [[-1 for i in range(100100)] for j in range(N+1)]
dp[0][0] = 0
for i in range(N):
    w, v = map(int, input().split())
    for j in range(W):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if dp[i][j] == -1:
            continue
        elif j+w <= W:
            # print("i:{},j:{},value1:{}".format(i,i+j,max(dp[i][j]+v, dp[i][j+w])))
            dp[i+1][j+w] = max(dp[i][j]+v, dp[i][j+w])
            # print(dp[i+1][j+w],i+1,j+w)

print(max(dp[N][:W+1]))

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string S, T;
  cin >> S >> T;

  int answer = 0;
  for (int i = 0; i < 3; ++i) {
    if (S[i] == T[i])
      answer++;
  }

  cout << answer << endl;
  return 0;
}


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

const ll mod = 1000000007;

int main(){
    int n; cin >> n;
    string s, t; cin >> s >> t;
    bool v = false, h = false;
    ll ans = 1;
    int idx = n;
    if(n >= 2){
        if(s[0] == s[1]){
            h = true;
            ans = 6;
            idx = 2;
        }
        if(s[0] != s[1]){
            v = true;
            ans = 3;
            idx = 1;
        }
    }   
    for(int i = idx; i < n; i++){
        if(i == n-1){
            if(v){
                ans *= 2;
                ans %= mod;
                break;
            }
        }
        if(s[i] == s[i+1]){
            if(v){
                ans *= 2;
                ans %= mod;
            }
            if(h){
                ans *= 3;
                ans %= mod;
            }
            ++i;
            v = false;
            h = true;
            continue;
        }
        if(s[i] != s[i+1]){
            if(v){
                ans *= 2;
                ans %= mod;
            }
            h = false;
            v = true;
            continue;
        }
    }
    if(n == 1) ans = 3;
    cout << ans << endl;
}

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

int n, h, a[100000], b[100000], maxA, ans;

int main() {
    cin >> n >> h;
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &a[i], &b[i]);
        maxA = max(maxA, a[i]);
    }
    sort(b, b + n);
    for (int i = n - 1; i >= 0; i--) {
        if (b[i] <= maxA || h <= 0) break;
        h -= b[i];
        ans++;
    }
    if (h > 0) {
        ans += ceil(h * 1.0 / maxA);
    }

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

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>

using namespace std;

int t[128];

int toint(string m)
{
	int res=0;
	for(int i=0,c=1;i<m.size();i++){
		if(isdigit(m[i]))
			c=m[i]-'0';
		else{
			res+=c*t[m[i]];
			c=1;
		}
	}
	return res;
}

string tomcxi(int n)
{
	ostringstream oss;
	for(int i=0,j=1000;i<4;n%=j,i++,j/=10){
		if(int c=n/j){
			if(c>=2)
				oss<<n/j;
			oss<<"mcxi"[i];
		}
	}
	return oss.str();
}

int main()
{
	for(int i=0,j=1000;i<4;i++,j/=10)
		t["mcxi"[i]]=j;
	
	int n; cin>>n;
	while(n--){
		string m1,m2; cin>>m1>>m2;
		cout<<tomcxi(toint(m1)+toint(m2))<<endl;
	}
	
	return 0;
}

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

#define Rep(b, e, i) for(int 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(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
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};

void solve(void){
    int A, B, K;
    cin >> A >> B >> K;
    if (B - A < 2*K) {
        Rep(A, B, n) {
            printf("%d\n", n);
        }
    }
    else {
        Rep(A, A+K-1, i) printf("%d\n", i);
        Rep(B-K+1, B, i) printf("%d\n", i);
    }
}

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


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

int main() {
    int n; cin >> n;
    ll ans = 0;
    vector<int> b(n-1);
    rep(i,n-1) cin >> b[i];
    ans += b[0] + b[n-2];
    vector<int> a(n);
    for (int i = 1; i < n-1; i++) a[i] = min(b[i], b[i-1]);
    
    rep(i,n) ans += a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

a = []
answer_array = []
for line in sys.stdin:
    a.append(map(int, line.strip().split()))
    #except StopIteration:
        #break

for i in range(len(a)):
    sum_up = a[i][0] + a[i][1]

    answer = len(str(sum_up))

    answer_array.append(answer)

for j in range(len(answer_array)):
    print answer_array[j]

Measured memory_bytes: 6292
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  string s;
  cin >> s;

  map<char, int> mp;

  REP(i, s.size()) mp[s[i]]++;
  REP(i, mp.size()){
    if(mp[i] >= 2){
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
MOD = 1e9 + 7
N, M = map(int, input().split())
ans = 1
if abs(N - M) > 1:
    print(0)
    sys.exit()
for n in range(2, N + 1):
    ans *= n
    ans %= MOD
for m in range(2, M + 1):
    ans *= m
    ans %= MOD
if N == M:
    ans *= 2
    ans %= MOD
print(int(ans))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;cin>>N;
    vi A(N),B(N),C(N);
    for(int i=0;i<N;i++){
        cin>>A[i];A[i]--;
    }
    for(int i=0;i<N;i++){
        cin>>B[i];
    }
    for(int i=0;i<N-1;i++){
        cin>>C[i];
    }
    ll ans=0;
    for(int i=0;i<N;i++){
        ans+=B[A[i]];
        if(i>0){
            if(A[i-1]==A[i]-1)ans+=C[A[i-1]];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}

int main(void){

    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d",a*b);
    
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
 
typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;
 
#define for01(k,n)  for (ll i=k; i<n; i++)
#define for02(k,n)  for (ll j=k; j<n; j++)
#define for03(k,n)  for (ll k=k; k<n; k++)
#define for11(k,n)  for (ll i=k; i<=n; i++)
#define for12(k,n)  for (ll j=k; j<=n; j++)
#define for13(k,n)  for (ll k=k; k<=n; k++)

#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define F first
#define S second
#define pp pair <ll, ll>
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define si size()
#define bk back()
#define deci(n)  fixed<<setprecision(n)

#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"


#define MAX LLONG_MAX

#define MIN LLONG_MIN

using namespace std;

int main()
{
  ll n,k;
  cin >> n >> k;
  
  ll *a = new ll[k];
  
  for01(0,k)
    cin >> a[i];
  
  
  sort(a,a+k);
  for(ll i = n; ;i++)
  {
    int f = 0;
    ll temp = i;
    
    while(temp!=0)
    {
      ll r = temp%10;
      
      for02(0,k)
      {
        if(a[j] == r)
        {
          f = 1;
          break;
        }
      }
      temp /= 10;
      if(f == 1)
        break;
    }
    if(f == 0)
    {
      
      p1(i);
      return 0;
    }
    f = 0;
  }
  /*string str = "";
  ll temp = n;
  while(temp!=0)
  {
    ll r = (n%10 + 1)%10;
    
    ll f = 0;
    for01(0,k)
    {
      if(r != a[i])
      {
        str += to_string(r);// + str;
        f = 1;
 		break;
      }
    }
    
    if(f == 0)
      str += to_string(r);// + str;
    
    temp/=10;
  }
  
  p1(str);*/
  return 0;
}

Measured memory_bytes: 256
k, _ = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

previous_pos  = (k - a.last) * -1
distances = []

a.each do | pos|
  distances.push(pos - previous_pos)
  previous_pos = pos
end

puts distances.inject(:+) - distances.max

Measured memory_bytes: 18364
def main():
    S = input()
    N = len(S)
    from collections import deque

    def solve(S):
        cur = deque([S[0]])
        ans1 = 1
        i = 1
        plus = 1
        while i < N:
            if i+plus > N:
                break
            if S[i:i+plus] in cur:
                plus += 1
            else:
                cur.popleft()
                cur.append(S[i:i+plus])
                i = i+plus
                plus = 1
                ans1 += 1

        cur = deque([S[:2]])
        ans2 = 1
        i = 2
        plus = 1
        while i < N:
            if i+plus > N:
                break
            if S[i:i+plus] in cur:
                plus += 1
            else:
                cur.popleft()
                cur.append(S[i:i+plus])
                i = i+plus
                plus = 1
                ans2 += 1
        return ans1, ans2
    ans1, ans2 = solve(S)
    ans3, ans4 = solve(S[::-1])
    print(max(ans1, ans2, ans3, ans4))


if __name__ == '__main__':
    main()


Measured memory_bytes: 44108
# AOJ 0039 Roman Figure
# Python3 2018.6.15 bal4u

roman = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M': 1000}

while True:
	try:
		p = list(input())
	except EOFError:
		break
	ans = i = 0
	while i < len(p):
		if i+1 < len(p) and roman[p[i]] < roman[p[i+1]]:
			ans += roman[p[i+1]] - roman[p[i]]
			i += 1
		else: ans += roman[p[i]]
		i += 1
	print(ans)


Measured memory_bytes: 5564
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int

using namespace std;


int main() {
	speed;
	int a, p;
	cin >> a >> p;
	a *= 3;
	int ans = 0;
	ans = (a + p) / 2;
	cout << ans;

	ed;
	return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)

using ll = long long;
const ll INF = 1001001001001001001ll;
inline int in() { int x; cin >> x; return x; }

struct edge { ll to, cost; };
typedef pair<int, int> P;
vector<edge> G[100005];
ll d[100005];
int V;

void dijkstra(int s)
{
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;

    if (d[v] < p.first) continue;
    REP(i, G[v].size()) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}


int main(void)
{
  V = in();
  REP(i, V - 1) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  int Q = in(), K = in();
  dijkstra(K - 1);
  REP(i, Q) {
    cout << d[in() - 1] + d[in() - 1] << endl;
  }
}



Measured memory_bytes: 9984
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <intrin.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>

using namespace std;

typedef long long ll;

void solve() {
	int n;
	cin >> n;
	vector<pair<pair<int, int>, int>> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i].first.first >> a[i].first.second >> a[i].second;

	sort(a.begin(), a.end(), [&](pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
		return a.first.first + a.first.second < b.first.first + b.first.second;
	});

	vector<ll> dp(20001, -1);
	dp[0] = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 20000; j >= 0; j--) {
			if (dp[j] == -1)
				continue;
			if (a[i].first.second >= j) {
				dp[j + a[i].first.first] = max(dp[j + a[i].first.first], dp[j] + a[i].second);
			}
		}
	}

	cout << *max_element(dp.begin(), dp.end());
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		//cout << '\n';
	}
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>

int main()
{
	std::vector<int> A;
	int ans = 0;
	while (1)
	{
		int n, x;
		std::cin >> n >> x;
		if (n == 0 && x == 0)
			break;
		for (int i = 1; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				for (int k = j + 1; k <= n; k++)
				{
					if (i + j + k == x)
						++ans;
				}
			}
		}
		A.push_back(ans);
		ans = 0;
	}

	for (std::vector<int>::iterator itr = A.begin(); itr != A.end(); itr++)
	{
		std::cout << *itr << '\n';
	}
}



Measured memory_bytes: 3140
#ABC 113 B - Palace
import numpy as np
def getNearestIndex(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
result = [0] * N

for i in range(N):
    result[i] = T - H[i] * 0.006

resultNum = getNearestIndex(result, A)
print(resultNum + 1)

Measured memory_bytes: 12488
import java.math.BigDecimal;
import java.util.*;
public class Main {

	public static void main(String[] args) 
	{
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		double num=sc.nextDouble();
		System.out.println(find(num));
	}

	private static BigDecimal find(double num) 
	{
		// TODO Auto-generated method stub
		double d=num/3;
		BigDecimal b=BigDecimal.valueOf(d);
		BigDecimal c=b.multiply(b);
		b=c.multiply(b);
		
		return (b);
		
	}

}


Measured memory_bytes: 23636
import Control.Applicative
import Control.Monad
import Data.List

solve :: [Int] -> Int
solve xs = iter 0 xs
  where
    iter k []  = k
    iter k [_] = k
    iter k (a:b:cs)
        | a == b    = let k' = k + 1 in k' `seq` iter k' cs
        | otherwise = iter k (b:cs)

main :: IO ()
main = do
    n <- readLn :: IO Int
    as <- fmap read . words <$> getLine :: IO [Int]
    print $ solve as

Measured memory_bytes: 892
k = list(map(int, input().split()))
a = list(map(int, input().split()))
n=k[0]
m=k[1]
d=0
e=0
for i in range (n):
    d+=a[i]

for j in range (n):
    if a[j]>=d/(4*m):
        e+=1

if e>=m:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 3060