akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
string s;
int sum;
stack<int> st;
stack<P> st2;
signed main() {
	cin >> s;
	rep(i, s.size()) {
		if (s[i] == '\\')st.push(i);
		else if (s[i] == '/' && !st.empty()) {
			if (!st2.empty() && st.top() < st2.top().first) {
				P p;
				while (!st.empty() && !st2.empty() && st.top() < st2.top().first) {
					p.second += st2.top().second;
					st2.pop();
				}
				p.first = st.top();
				p.second += i - st.top();
				st2.push(p);
			}
			else st2.push(make_pair(st.top(), i - st.top()));
			sum += i - st.top();
			st.pop();
		}
	}
	cout << sum << endl;
	vector<int> ans;
	while (!st2.empty()) {
		ans.push_back(st2.top().second);
		st2.pop();
	}
	if (ans.empty()) {
		cout << 0 << endl;
		return 0;
	}
	cout << ans.size() << " ";
	for (int i = (int)ans.size() - 1; i > 0; i--)cout << ans[i] << " ";
	cout << ans[0] << endl;
}


Measured memory_bytes: 3252
N = int(input())
a = list(map(int, input().split(" ")))
count = [0, 0, 2]
for num in a:
    if num % 2 == 0:
        if num % 4 == 0:
            count[2] += 1
        else:
            count[1] += 1
    else:
        count[0] += 1

need_4 = count[0]
if count[1] > 0:
    need_4 += 1
if count[2] - need_4 > 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

string lpad(string l,int s,int n){
    string temp = to_string(n);
    string res = "";
    int loop = s - temp.size();
    while(loop--) res+=l;

    return res+temp;
}

int main()
{
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k ;

    printIf(e-a>k,":(","Yay!")
}

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

int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  
  int sum = 0;
  if (A >= K){
    sum += K;
  } else if (A < K){
    sum += A;
    K -= A;
    if (B >= K){
      sum -= 0;
    } else if (B < K){
      K -= B;
      sum -= K;
    }
  }
  
  cout << sum << endl;

}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <fstream>
#include <map>
#include <math.h>
#include <climits>
using namespace std;


int main(){
  int x, a, b;
  cin >> x >> a >> b;
  
  if(a + x >= b){
    if(b<=a) cout << "delicious" << endl;
    else cout << "safe" << endl;
  }else{
    cout << "dangerous" << endl;
  }
  
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(void){
  int n,m;
  while(cin >> n >> m){
    if((n|m) == 0) break;

    int d[n][n];
    int numv = 0;
    fill((int *)d, (int *)d+n*n, 10000000);
    for(int i=0;i<n;i++){
      d[i][i] = 0;
    }

    map<string,int> assoc;
    string start,mid,end;
    cin >> start >> mid >> end;
    assoc[start] = 0;
    assoc[mid] = 1;
    assoc[end] = 2;
    numv = 3;
    for(int i=0;i<m;i++){
      string s,e;
      int dist,delay;
      cin >> s >> e >> dist >> delay;
      if(assoc.find(s) == assoc.end()){
	assoc[s] = numv;
	//cerr << s << " = "<< numv << endl;
	numv++;
      }
      if(assoc.find(e) == assoc.end()){
	assoc[e] = numv;
	//cerr << e << " = "<< numv << endl;
	numv++;
      }
      d[assoc[s]][assoc[e]] = dist / 40 + delay;
      d[assoc[e]][assoc[s]] = dist / 40 + delay;
    }
    /*
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	printf("d[%d][%d] = %d\n", i,j,d[i][j]);
      }
    }
    */
    //warshall-floyd
    for(int k=0;k<n;k++){
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
	}
      }
    }

    cout << d[0][1] + d[1][2] << endl;
  }
}

Measured memory_bytes: 1936
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

S = i()
time = []

for i in range(S):
    a = l()
    a.reverse()
    time.append(a)

time.sort()

pl = 0

for i in range(S):
    pl += time[i][1]
    if pl > time[i][0]:
        print("No")
        sys.exit()

print("Yes")


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

#define pb push_back
#define mp make_pair

typedef long long ll;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int dp[100001];

int main()
{
  int n, k;
  cin >> n >> k;
  
  int h[n];
  for(int i = 0; i < n; i++){
    cin >> h[i];
    dp[i] = inf;
  }

  dp[0] = 0;

  for(int i = 0; i < n; i++){
    for(int j = 1; j <= k; j++){
      if(i+j < n){
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
      }
    }
  }

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

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){

    return;
}


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int rs = 0;
    int l,r,d;
    cin >> l >> r >> d;
    for (int i = l; i <= r; i++){
        if (i % d == 0){
            rs++;
        }
    }
    ctn(rs);
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   cin>>n;

   string s;
   cin>>s;

   int red = 0, blue = 0;
   for (int i = 0; i < n; ++i)
   {
      red += (s[i] == 'R');
      blue += (s[i] == 'B');
   }

   if (red > blue){
      cout<<"Yes\n";
   }
   else{
      cout<<"No\n";
   }

   #warning make sure N size is correct!
   return 0;
}

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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	int n; cin >> n;
	vi a(n); cin >> a;
	map<int, int> prv;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += prv[i - a[i]];
		prv[a[i] + i]++;
	}
	cout << ans << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 21088
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    rep(i,0,n-2)
    {
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
            ans++;
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 100005
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, k, sum, w[MAXN], v[MAXN];
LL ans, f[MAXN];

int main()
{
	memset(f, 0x3f, sizeof(f));
	scanf("%d%d", &n, &k);
	for(rint i=1; i<=n; ++i) scanf("%d%d", &w[i], &v[i]), sum+=v[i];
	f[0]=0;
	for(rint i=1; i<=n; ++i)
	{
		for(rint j=sum; j>=v[i]; j--) f[j]=min(f[j], f[j-v[i]]+w[i]);
	}
	//for(rint i=sum; i>=0; i--) printf("%d %lld!!\n", i, f[i]);
	for(rint i=sum; i>=0; i--)
		if(f[i]<=k) {printf("%d\n", i); break;}
	return 0;
}

Measured memory_bytes: 896
//
// Created by MengHaitao on 2019/11/29 0029.
//
#include <iostream>
using namespace std;
int n,x,y=1;
int gcd(int a,int b){
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main(){
    cin>>n;
    while(n--) {
        cin>>x,y=x*y/gcd(x,y);
    }
    cout<<y<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,x;
void output(){
	puts("-1");exit(0);
}
int main(){
	int n;cin>>n;
	cin>>a>>b;ll N=a+b;
	for(int i=3;i<=n;i++)cin>>x,c^=x;
	if(c>N)output();
	if((N-c)%2)output();
	ll W=(N-c)/2,A=W;
	if(W>a)output();
	if(W&c)output();
	for(int i=56;i>=0;i--)
		if((1ll<<i)&c)
			if(A+(1ll<<i)<=a)A+=(1ll<<i);
	if(A==0)output();
	cout<<a-A; 
}

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

typedef long long ll;

ll a[2],c[2];

void Input(){
	cin>>a[0]>>a[1]>>c[0]>>c[1];
}

void Solve(){
	ll maxim=-1e18;
	for(int i=0; i<2; i++)for(int j=0; j<2; j++){
		maxim=max(a[i]*c[j],maxim);
	}
	cout<<maxim<<'\n';
}

int main(){
	Input();
	Solve();
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(){
  int a, b, c, k;
  scanf("%d %d %d", &a, &b, &c);
  scanf("%d", &k);
  
  while(b <= a){
    b *= 2;
    k--;
  }
  
  while(c <= b){
    c *= 2;
    k--;
  }
  
  if(k >= 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  
  return 0;
}
  

Measured memory_bytes: 1648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    
    int star = (int)S.find('*');
    int l = 0, r = 0;
    for(int i = 0; i < star;i++){
        if(S[i] == '(') l+=1;
        else l = max(0,l-1);
    }
    for(int i = (int)S.length()-1; i > star;i--){
        if(S[i] == ')') r+=1;
        else r = max(0,r-1);
    }
    res = min(l,r);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    
    return 0;
}



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

int main(){
    vector<int> isprime(1e5+1,1);
    isprime[0]=isprime[1]=0;
    vector<long long int> primes;
    for(int i=0;i<1e5+1;i++){
        if(isprime[i]){
            primes.push_back(i);
            for(int j=i*2;j<1e5+1;j+=i)
                isprime[j]=0;
        }

    }
    int m,a,b;
    while(cin>>m>>a>>b,m){
        int p,q;
        long long int res=0;
        for(int pindex=0;pindex<primes.size();pindex++){
            for(int qindex=pindex;qindex<primes.size()&&primes[pindex]*primes[qindex]<=m;qindex++)
            if(a*primes[qindex]<=primes[pindex]*b && primes[qindex]*primes[pindex]>res){
                p=primes[pindex];
                q=primes[qindex];
                res=p*q;
            }



        }
        cout<<p<<" "<<q<<endl;


    }

}

Measured memory_bytes: 3424
#include <stdio.h>
#include <string.h>
#define MAX 101

int main(void) {
    int n, v, t = 0, h = 0;
    char tc[MAX], hc[MAX];
    for(scanf("%d", &n); n--; v || (t++, h++)) {
        scanf("%s %s", tc, hc);
        v = strcmp(tc, hc);
        v && (*(v > 0 ? &t : &h) += 3);
    }
    printf("%d %d\n", t, h);
    return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,ans=-10001;
	cin>>a>>b;
	if(ans<a+b)ans=a+b;
	if(ans<a-b)ans=a-b;
	if(ans<a*b)ans=a*b;
	cout<<ans<<endl;
}


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


int main()
{

    int n,k,i,j,p,c=0;
    int num[100010];
    set<int>s;

    cin>>n>>k;
    for(i=1; i<n; i++)
    {
        cin>>num[i];
        s.insert(num[i]);
    }
    if(s.size()==1)
        cout<<"0"<<endl;
    else
    {
        c=1;
        n=n-k;
        while(n>=k)
        {
            n=n-(k-1);
            c++;
        }

        if(n!=0)
            c++;

        cout<<c<<endl;
    }
    return 0;

}


Measured memory_bytes: 5376
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"def fact(n):\n"
"  v = 1\n"
"  for i in range(2, n + 1):\n"
"    v = v * i % 1000000007\n"
"  return v\n"
"\n"
"n, m = map(int, input().split())\n"
"if abs(n - m) > 1:\n"
"  print('0')\n"
"elif n == m:\n"
"  print(2 * fact(n) * fact(m) % 1000000007)\n"
"else:\n"
"  print(fact(n) * fact(m) % 1000000007)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const int PI = acos(-1);
int main(){
	int a,b,m;cin>>a>>b>>m;
	int A[a],B[b];
	int am =INF,bm=INF;
	rep(i,a){
		cin>>A[i];
		am =min(am,A[i]);
	}
	rep(i,b){
		cin>>B[i];
		bm =min(bm,B[i]);
	}
	int ans =am+bm;
	rep(i,m){
		int x,y,z;
		cin>>x>>y>>z;
		x--;y--;
		ans=min(ans,A[x]+B[y]-z);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

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

int main() {
  map<char, bool> mp;

  string s;
  cin >> s;

  for (char c : s) {
    mp[c] = true;
  }

  if (mp['N'] == mp['S'] && mp['W'] == mp['E']) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<int,P>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main(){
	int a,b;
	cin>>a>>b;
	cout<<a*a-b<<endl;
	return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define MOD 1000000007

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;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int n;
  cin >> n;

  vector<map<string, ll>> m(n);

  for (char c1 : "ACGT"s)
    for (char c2 : "ACGT"s)
      for (char c3 : "ACGT"s) {
        string s = {c1, c2, c3};
        // cout << s << endl;
        if (s == "AGC"s or s == "ACG"s or s == "GAC"s)
          m[2][s] = 0;
        else
          m[2][s] = 1;
      }

  FOR(i, 3, n) {
    for (char c1 : "ACGT"s)
      for (char c2 : "ACGT"s)
        for (char c3 : "ACGT"s) {
          string s = {c1, c2, c3};
          if (s == "AGC"s or s == "ACG"s or s == "GAC"s)
            m[i][s] = 0;
          else {
            for (char c4 : "ACGT"s) {
              string xx = {c1, c3, c4};
              string yy = {c1, c2, c4};
              if (xx == "AGC"s or yy == "AGC"s)
                continue;
              else {
                string ps = {c1, c2, c3};
                string ns = {c2, c3, c4};

                if (ns == "AGC"s or ns == "ACG"s or ns == "GAC"s)
                  m[i][ns] = 0;
                else {
                  m[i][ns] += m[i - 1][ps];
                  m[i][ns] %= MOD;
                }
              }
            }
          }
        }
  }

  ll ans = 0;

  for (char c1 : "ACGT"s)
    for (char c2 : "ACGT"s)
      for (char c3 : "ACGT"s) {
        string s = {c1, c2, c3};
        ans += m[n - 1][s];
        ans %= MOD;
      }

  // for (auto p : m[n - 1]) {
  //   cout << p.first << " " << p.second << endl;
  // }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,n,x=1;
    cin>>n>>a>>b;
    x=n*a;
    if(x<b)
    {
        cout<<x<<endl;
    }
    else
    {
        cout<<b<<endl;
    }
}


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

int main(){
    int a,b,c;
    long long ans=0;
    cin >>a>>b>>c;

    ans=min(c,b)*2;
    if(b >c){
  
        b=b-c;
        c = 0;
    }else{
        c=c-b;
        b=0;
    }

    
    
               // cout <<ans<<endl;

                //cout <<b<<" "<<c<<endl;
    ans=ans+min(a+1,c)+b;

    cout <<ans<<endl;

   
       
   
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

main {
  int a, b;
  string op;
  while (cin >> a >> op >> b, op != "?") {
    if (op == "+") cout << a + b << endl;
    if (op == "-") cout << a - b << endl;
    if (op == "*") cout << a * b << endl;
    if (op == "/") cout << a / b << endl;
  }
}

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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  bool kaibun = true;
  for(int i=0; i<=(N-1)/2; i++){
    if(S[i]!=S[N-1-i]){
      kaibun = false;
    }
  }
  
  for(int i=0; i<=(N-1)/4; i++){
    if(S[i]!=S[(N-1)/2-1-i]){
      kaibun = false;
    }
    if(S[(N+3)/2-1+i]!=S[N-1-i]){
      kaibun = false;
    }
  
  }
  if(kaibun==true) cout << "Yes" <<endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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 long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ld n,m,all=0;
    cin >> n >> m;
    ld a[(ll)n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
        all+=a[i];
    }
    sort(a,a+(ll)n);
    for (ll i=0;i<m;i++){
        if (a[(ll)n-1-i]<all/(4*m)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void quicksort(int a[], int left, int right){
    int p;
	int L = left, R = right;
	int temp;
	p = a[(left + right) / 2];

	while (1){
		while (a[L] < p) L++; while (a[R] > p)
			R--;
		
		if (L >= R)
			break;

		temp = a[R];
		a[R] = a[L];
		a[L] = temp;

		L++;
		R--;
	}
	if (left < L - 1) quicksort(a, left, L - 1);
    if (right > R + 1)quicksort(a, R + 1, right); 
	
}

int main(){
    int a, b, n, i, j, k;
    int A[52];
    int B[52];
    int tmp;
    int x = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
        B[i] = A[i];
    }
    quicksort(A, 0, n - 1);
    for(i = 0; i < n; i++){
        for(j = i; j < n; j++){
            x = 0;
            tmp = B[i];
            B[i] = B[j];
            B[j] = tmp;
            for(k = 0; k < n; k++){
                if(A[k] != B[k]){
                    x = 1;
                    break;
                }
            }
            if(x == 0){
                printf("YES\n");
                break;
            }
            tmp = B[i];
            B[i] = B[j];
            B[j] = tmp;
        }
        if(x == 0){
            break;
        }
    }
if(x == 1){
    printf("NO\n");
}
    return 0;
}

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

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

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < 2; i++) {
		if (s[i] != s[i+1]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()



int main() {
	int K;
	cin >> K;
	int a[32] = { 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 };
	cout << a[K-1] << endl;
	return 0;
}


Measured memory_bytes: 256
S = input()
l = len(S)
ans = 0
if S[0] == 'k':
	ans += 1
	if S[1] == 'e':
		ans += 1
		if S[2] == 'y':
			ans += 1
			if S[3] == 'e':
				ans += 1
				if S[4] == 'n':
					ans += 1
					if S[5] == 'c':
						ans += 1
						if S[6] == 'e':
							ans += 1
if S[l-1] == 'e':
	ans += 1
	if S[l-2] == 'c':
		ans += 1
		if S[l-3] == 'n':
			ans += 1
			if S[l-4] == 'e':
				ans += 1
				if S[l-5] == 'y':
					ans += 1
					if S[l-6] == 'e':
						ans += 1
						if S[l-7] == 'k':
							ans += 1
if ans >=7 :
	print('YES')
else:
	print('NO')


Measured memory_bytes: 3064
S = input()

N = len(S)
a = (N - 1) // 2
b = (N + 3) // 2

A = S[0:a]
B = S[b-1:N]
ans = 'Yes'

for i in range((len(B) // 2 + 1)):
    if B[i] != B[-i-1]:
        ans = 'No'
        break

for i in range(len(A) // 2 + 1):
    if A[i] != A[-i-1]:
        ans = 'No'
        break

if A != B: ans = 'No'

print(ans)

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

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

  long long ans = 0;
  map<int, int> mp;
  for ( int i = 1; i <= n; i++ ) {
    int ai;
    cin >> ai;
    ans += mp[i-ai];
    mp[i+ai]++;
  }

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


Measured memory_bytes: 20620
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;
bool f(int a, int b , int c) {
  if(a+b>=c) return true;
  else return false;
}
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  yorn(f(a, b, c));
  return 0;
}

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

int main() {
  int x,n,m; cin>>x>>n>>m;
  if (abs(x-n)>abs(x-m)) cout<<"B"<<endl;
  else cout<<"A"<<endl;
}


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

int main() {
    string str1, str2;
    cin >> str1 >> str2;
    int ans = 1e9;
    for(int i = 0; i <= str1.length() - str2.length(); i++){
        int count = 0;
        for(int j = 0; j < str2.length(); j++){
            if(str1[i+j] == str2[j]) continue;
            count++;
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
let to_list str =
  let rec doit i acc =
    if i < 0 then acc
    else doit (i - 1) (String.get str i :: acc) in
  doit (String.length str - 1) []

let (height, width) = (8, 8)

let read_ns () = read_line () |> to_list |> List.map (fun e -> Char.code e - Char.code '0')

let check t i j =
  let a i j = i+1 < height && j+1 < width && List.for_all ((=) 1) [t.(i).(j); t.(i).(j+1); t.(i+1).(j); t.(i+1).(j+1)] in
  let b i j = i+3 < height && List.for_all ((=) 1) [t.(i).(j); t.(i+1).(j); t.(i+2).(j); t.(i+3).(j)] in
  let c i j = j+3 < width && List.for_all ((=) 1) [t.(i).(j); t.(i).(j+1); t.(i).(j+2); t.(i).(j+3)] in
  let d i j = i+2 < height && j-1 >= 0 && List.for_all ((=) 1) [t.(i).(j); t.(i+1).(j-1); t.(i+1).(j); t.(i+2).(j-1)] in
  let e i j = i+1 < height && j+2 < width && List.for_all ((=) 1) [t.(i).(j); t.(i).(j+1); t.(i+1).(j+1); t.(i+1).(j+2)] in
  let f i j = i+2 < height && j+1 < width && List.for_all ((=) 1) [t.(i).(j); t.(i+1).(j); t.(i+1).(j+1); t.(i+2).(j+1)] in
  let g i j = i+1 < height && j-1 >= 0 && j+1 < width && List.for_all ((=) 1) [t.(i).(j); t.(i).(j+1); t.(i+1).(j-1); t.(i+1).(j)] in
  let rec doit = function
    | [] -> assert false
    | (f, s) :: tl ->
      if f i j then s
      else doit tl in
  doit [(a, "A"); (b, "B"); (c, "C"); (d, "D"); (e, "E"); (f, "F"); (g, "G")]

let () =
  try
    while true do
      let t = Array.make_matrix height width 0 in
      for i = 0 to height - 1 do
        let rec doit j = function
          | [] -> ()
          | hd :: tl ->
            t.(i).(j) <- hd;
            doit (j + 1) tl in
        read_ns () |> doit 0;
      done;
      let rec doit = function
        | (i, _) when i = height -> assert false
        | (i, j) when j = width -> doit (i + 1, 0)
        | (i, j) ->
          if t.(i).(j) = 1 then (check t i j |> print_endline)
          else doit (i, j + 1) in
      doit (0, 0);
      read_line () |> ignore;
    done
  with _ -> ()

Measured memory_bytes: 2236
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
dp_a = [L[0][0]]
dp_b = [L[0][1]]
dp_c = [L[0][2]]
for i in range(N-1):
  dp_a.append(max(dp_b[i]+L[i+1][0],dp_c[i]+L[i+1][0]))
  dp_b.append(max(dp_a[i]+L[i+1][1],dp_c[i]+L[i+1][1]))
  dp_c.append(max(dp_a[i]+L[i+1][2],dp_b[i]+L[i+1][2]))
print(max(dp_a[N-1],dp_b[N-1],dp_c[N-1]))

Measured memory_bytes: 42504
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



flag = 1
n = I()
A = LI()
ret = 0
cumsum = 0
for i in range(n):
    cumsum += A[i]
    if flag and cumsum <= 0:
        ret += 1 - cumsum
        cumsum = 1
    elif not flag and cumsum >= 0:
        ret += cumsum + 1
        cumsum = -1
    flag ^= 1


ans = ret
ret = 0
flag = 0
cumsum = 0
for i in range(n):
    cumsum += A[i]
    if flag and cumsum <= 0:
        ret += 1 - cumsum
        cumsum = 1
    elif not flag and cumsum >= 0:
        ret += cumsum + 1
        cumsum = -1
    flag ^= 1


print(min(ans, ret))

Measured memory_bytes: 59504
#include <cstdio>
#include <algorithm>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' ')

const int INF = 1000000000;
const int N_MAX = 100;

int N, M;
int d[N_MAX][N_MAX];
int prv[N_MAX][N_MAX];

void warshall_floyd() {
  REP(i, N) REP(j, N) prv[i][j] = i;
  REP(k, N) REP(i, N) REP(j, N) {
    if (d[i][j] > d[i][k] + d[k][j]) {
      d[i][j] = d[i][k] + d[k][j];
      prv[i][j] = prv[k][j];
    }
  }
}

void solve() {
  warshall_floyd();
  int used = 0;
  REP(i, N) REP(j, N) {
    if (i != j && prv[i][j] == i) used++;
  }
  printf("%d\n", M - used / 2);
}

void input() {
  scanf("%d%d", &N, &M);
  fill(d[0], d[N], INF);
  REP(i, N) d[i][i] = 0;
  REP(i, M) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    d[a - 1][b - 1] = d[b - 1][a - 1] = c;
  }
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    char x, y;
 	cin >> x >> y;
  	if (x > y) cout << ">" << endl;
 	else if (x < y) cout << "<" << endl;
  	else cout << "=" << endl;
    return 0;
}



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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[])
{
  int n;
  ll k;
  cin >> n >> k;

  vector<ll> positive_nums, negative_nums;
  ll z = 0;
  for (int i = 0; i < n; i++) {
    ll num;
    cin >> num;
    if (num > 0) {
      positive_nums.push_back(num);
    } else if (num < 0) {
      negative_nums.push_back(num);
    } else {
      z++;
    }
  }

  sort(positive_nums.begin(), positive_nums.end());
  sort(negative_nums.begin(), negative_nums.end());
  
  ll p_size = positive_nums.size(),
     n_size = negative_nums.size(),
     negative_cnt = p_size * n_size,
     zero_cnt = z * (p_size + n_size) + z * (z - 1) / 2,
     ans;

  if (negative_cnt >= k) {
    ll left = -1e18 - 1ll, right = -1;
    while (right - left > 1) {
      ll mid = (left + right) / 2;
      ll cnt = accumulate(positive_nums.begin(), positive_nums.end(), 0ll,
          [&](auto acc, auto num) {
            auto right_it = upper_bound(
                negative_nums.begin(),
                negative_nums.end(),
                (mid - num + 1) / num);
            return acc + distance(negative_nums.begin(), right_it);
          });

      if (cnt < k) {
        left = mid;
      } else {
        right = mid;
      }
    }

    ans = right;
  } else if (negative_cnt + zero_cnt >= k) {
    ans = 0;
  } else {
    ll left = 1, right = 1e18 + 1ll;
    while(right - left > 1) {
      ll mid = (left + right) / 2;
      ll cnt = negative_cnt + zero_cnt;
      if (positive_nums.size() > 1) {
        for (auto it = positive_nums.begin(); it != positive_nums.end() - 1; it++) {
          auto right_it = upper_bound(
              it + 1,
              positive_nums.end(),
              mid / *it);
          cnt += distance(it + 1, right_it);
        }
      }

      if (negative_nums.size() > 1) {
        for (auto it = negative_nums.begin(); it != negative_nums.end() - 1; it++) {
          auto left_it = lower_bound(
              it + 1,
              negative_nums.end(),
              mid / *it);
          cnt += distance(left_it, negative_nums.end());
        }
      }

      if (cnt < k) {
        left = mid;
      } else {
        right = mid;
      }
    }

    ans = right;
  }

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

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

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

  if (N%500 == 0) {
    cout << "Yes" << endl;
  }
  else if (N%500 <= A){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
    }
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

ll Sum(const vector<int>&v,int k){
  int n = (int)v.size();
  ll sum = -1001001001001001;
  for(int i = 0; i < n; ++i){
    ll tmp = 0;
    for(int j = 0; j < k; ++j){
      tmp += v[(i+j)%n];
      sum = max(sum,tmp);
    }
  }
  return sum;
}

int main(){
  int n,k; cin >> n >> k;
  vector<int> p(n),c(n); cin >> p >> c;
  for(auto&e:p)e--;
  bitset<6000> vst;
  ll ans = -1001001001001001;
  for(int i = 0; i < n; ++i){
    if(vst[i])continue;
    vst[i] = 1;
    vector<int> v;
    int pos = i;
    while(1){
      v.push_back(c[pos]);
      pos = p[pos];
      if(pos == i)break;
      vst[pos] = 1;
    }
    int vsize = (int)v.size();
    if(k <= vsize){
      ans = max(ans,Sum(v,k));
    } else {
      ll tmp = Sum(v,vsize);
      ans = max(ans,tmp);
      ll sum = 0;
      for(auto e:v)sum += e;
      ans = max(ans,sum*(k/vsize)+max(Sum(v,k%vsize),0LL));
      ans = max(ans,sum*(k/vsize-1)+tmp);
    }
  }  
  cout << ans << endl;
  return 0;
}


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

const int MAX = 200000;
const int ADD = 100001;

int a[100010];
int T[200010];
int n;

void add(int x, int v){
	while (x <= MAX){
		T[x] += v;
		x += x & -x;
	}
}

int query(int x){
	int res = 0;
	while (x){
		res += T[x];
		x -= x & -x;
	}
	return res;
}

int sum[100010];

int check(int x){
	memset(T, 0, sizeof(T));
	long long res = 0;
	add(ADD, 1);
	for (int i = 0; i < n; i++){
		sum[i] = a[i] >= x ? 1 : -1;
		if (i) sum[i] += sum[i - 1];
//		cout << "  sum:" << sum[i] << endl;
		res += query(sum[i] + ADD);
//		cout << "  " << i << " " << query(sum[i] + ADD) << endl;
		add(sum[i] + ADD, 1);
	}
//	cout << x << " " << res << endl;
	return res >= 1ll * n * (n + 1) / 4;
}

int main(){
	scanf("%d", &n);
	int maxj = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		maxj = max(maxj, a[i]);
	}
	int l = 0, r = maxj;
//	cout << check(8) << endl;
	while (l < r){
		int mid = (l + r + 1) >> 1;
//		cout << l << " " << r << " " << mid << " " << check(mid) << endl;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	printf("%d\n", l);
	return 0;
}


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

int main(){

int num = 0;
int *data;
int i;
int k;
int count = 0;
int finalans = 0;

while(1){
  scanf("%d",&num);
  if(1 <= num && num <=10000){
    break;
  }
}

data = (int *)malloc(sizeof(int)*num);

for(i = 0;i < num;i++){
  scanf("%d",&data[i]);
if(data[i] > 2 && data[i] % 2 == 0){
  continue;
}
  for(k = 2;k <= sqrt(data[i]);k++){
   if(data[i] % k == 0){
    count = 1;
   }
}
if(count != 1){
  finalans++;
}
count = 0;
}

printf("%d",finalans);
printf("\n");
return 0;
}



Measured memory_bytes: 2064
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;

#define M 1000010


int main(){
	IOS;
	tihs;

	string s,t;cin>>s>>t;
	string s1;
	rep(i,0,26){
		char c=i+'a';
		s1=s;
		s1+=c;
		if(s1==t){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";

	return 0;
}

	

Measured memory_bytes: 3648
#include<cstdio>

int S[1000000],T[500000];

int binarySearch(int x,int n){
  int key = T[x];
  int left = 0;
  int right = n;
  int mid;
  
  while(left < right){
    mid = (left + right) / 2;
    if(S[mid] == key){
      return mid;
    }else if(key < S[mid]){
      right = mid;
    }else{
      left = mid + 1;
    }
  }

  return -1;
}

int main(){
  int n,q,cnt = 0;
  int ans;
  std::scanf("%d",&n);

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

  std::scanf("%d",&q);

  for(int i = 0;i < q;i++){
    std::scanf("%d",&T[i]);
  }

  for(int i = 0;i < q;i++){
    ans  = binarySearch(i,n);
    if(ans != -1){
      cnt++;
    }
  }
  
  std::printf("%d\n",cnt);

  return 0;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
typedef pair<pair<lint, int>, pair<int, int>> ppp;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9 + 7;
const lint INF = mod*mod;
const int MAX = 100010;

int main(){
    int n, K;
    scanf("%d%d", &n, &K);
    int a[n], sum[n+1];
    sum[0]=0;
    rep(i, n){
        scanf("%d", &a[i]);
        --a[i];
        a[i]%=K;
        sum[i+1]=sum[i]+a[i];
        if(sum[i+1]>=K) sum[i+1]-=K;
    }
    lint ans=0;
    map<int, lint> mp;
    rep(i, min(n+1, K)) ++mp[sum[i]];
    rep(i, n){
        ans+=mp[sum[i]]-1;
        if(i+K<=n) ++mp[sum[i+K]];
        --mp[sum[i]];
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	long double l; cin >> l;
	cout << fixed << setprecision(10) << l/3*l/3*l/3 << endl;
}

Measured memory_bytes: 256
a = list(map(int, input().split()))

if a[2]%a[1]==0:
  T = a[2]//a[1]
else:
  T = a[2]//a[1]+1

if a[0]%a[3]==0:
  A = a[0]//a[3]
else:
  A = a[0]//a[3]+1

if T<= A:
  print('Yes')
else:
  print('No')
    

Measured memory_bytes: 9060
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
constexpr auto MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    vector<bool> p(100001, true);
    p[0] = false, p[1] = false;
    eFOR(i, 2, 100000)if (p[i]) {
        for (int j = 2 * i; j <= 100000; j += i)p[j] = false;
    }

    VI ans(100001, 0);
    for (int i = 3; i <= 100000; i += 2)if (p[i] && p[(i + 1) / 2])ans[i]++;
    eFOR(i, 1, 100000)ans[i] += ans[i - 1];

    int q;
    cin >> q;
    int l, r;
    FOR(i, 0, q) {
        cin >> l >> r;
        cout << ans[r] - ans[l - 1] << "\n";
    }

}

Measured memory_bytes: 1024
N = int(input().rstrip())
Idxs = [int(x) for x in input().rstrip().split()]
Bs = [int(x) for x in input().rstrip().split()]
Cs = [int(x) for x in input().rstrip().split()]

ret = 0
prev = -100
for idx in Idxs:
    ret += Bs[idx-1]
    if idx-1 == prev:
        ret += Cs[prev-1]
    prev = idx
print(ret)


Measured memory_bytes: 3060