akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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>
struct BinaryIndexedTree{
   vector<T> data;
   BinaryIndexedTree(int sz){
       data.assign(sz+1, 0);
   }
   // 区間[0,k]の合計 sum(v[0]~v[k])
   T sum(int k){
       T ret=0;
       for(++k;k>0;k-=(k&-k)) ret+=data[k];
       return ret;
   }
   // v[a]+=x
   void add(int k,T x){
       for(++k;k<data.size();k+=(k&-k)) data[k]+=x;
   }
   // wを超える最小のv[i]のiを返す(0indexedのを返す)(data上のindexを返したいならreturn x+1)
   int lower_bound(T w){//T?
       if(w<=0) return 0;
       //左右どっちに行くか考える
       int x=0,r=1;
       while(r<data.size()) r<<=1;
       for(int k=r;k>0;k>>=1){
           if(x+k<=data.size()&&data[x+k]<w){
               //左部分を引いて右へ，再起っぽい
               w-=data[x+k];
               x+=k;
           }
       }
       // return x+1;
       return x;
   }
};


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

    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        a[i]-=k;
    }
    vector<ll> sum(n+1,0);
    rep(i,n) sum[i+1]=sum[i]+a[i];
    map<ll,int> id;
    vector<ll> sub=sum;
    sort(ALL(sub));
    int cnt=1;
    rep(i,n+1){
        if(id.count(sub[i])) continue;
        id[sub[i]]=cnt;cnt++;
    }
    BinaryIndexedTree<ll> BIT(cnt+10);
    rep(i,n+1){
        BIT.add(id[sum[i]],1);
    }
    ll ans=0;
    rep(i,n){
        BIT.add(id[sum[i]],-1);
        //id[sum[i]]以上のものを数えたい
        ans+=BIT.sum(cnt+5)-BIT.sum(id[sum[i]]-1);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 19072
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    int k = ceil((-1 + sqrt(1 + 8*n)) / 2);
    int e = k*(k+1)/2 - n;
    For1(i, k) if(i != e) Cout(i);
}





Measured memory_bytes: 256
#include<iostream>
#define A 1
#define C 2
#define G 3
#define T 4
using namespace std;
typedef long long ll;

const int MAX_N = 101;
const ll MOD = 1e9 + 7;

int N;
ll memo[MAX_N][5][5][5][5];

ll dfs(int i, int c1, int c2, int c3, int c4) {
    // i-4, i-3, i-2, i-1文字目がc1, c2, c3, c4の時のi文字目までの通り数
    if (c2 == A && c3 == G && c4 == C) return 0;
    if (c2 == A && c3 == C && c4 == G) return 0;
    if (c2 == G && c3 == A && c4 == C) return 0;
    if (c1 == A && c2 == G && c3 == G && c4 == C) return 0;
    if (c1 == A && c2 == G && c3 == T && c4 == C) return 0;
    if (c1 == A && c2 == T && c3 == G && c4 == C) return 0;
    if (i == N) return 1;
    if (memo[i][c1][c2][c3][c4] > 0) return memo[i][c1][c2][c3][c4];
    for (int j = 1; j <= 4; j++) {
        memo[i][c1][c2][c3][c4] = (memo[i][c1][c2][c3][c4] + dfs(i + 1, c2, c3, c4, j)) % MOD;
    }
    return memo[i][c1][c2][c3][c4];
}

int main() {
    cin >> N;
    cout << dfs(0, T, T, T, T) << endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N=200005;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int f[N],a[N],cnt[N];
int main(){
	int n=read(),m=read();
	for (int i=1;i<=n;i++) a[i]=read(),cnt[a[i]]++;
	for (int i=1;i<=n;i++){
		if (cnt[i]){
			for (int j=max(0,i-cnt[i]);j<i;j++) f[j]++;
		}
	}
	int ans=0;
	for (int i=0;i<n;i++){
	if (!f[i]) ans++;  }
	for (int i=1;i<=m;i++){
		int u=read(),y=read();
		int x=a[u];
		a[u]=y;
		if (x-cnt[x]>=0){
			f[x-cnt[x]]--;
			if (f[x-cnt[x]]==0) ans++;
		}
		cnt[x]--;
		if (y-cnt[y]-1>=0){
			f[y-cnt[y]-1]++;
			if (f[y-cnt[y]-1]==1) ans--;
		}
		cnt[y]++;
		printf("%d\n",ans);
	}
	return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >>c;
    int ans = 1;
    if(a==b){
        if(a!=c)ans=2;
    }else{
        if(a!=c&&b!=c)ans=3;
        else ans = 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int H = sc.nextInt();
			int W = sc.nextInt();
			
			if(H==0&&W==0) break;
			
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					System.out.print("#");
				}
				
				System.out.println("");
			}
			System.out.println("");
		}
	}

}



Measured memory_bytes: 34752
h, w = map(int, input().split())
a = {}
for i in range(h):
    s = input()
    for i in s:
        a.setdefault(i, 0)
        a[i] += 1
a2 = 0
a1 = 0
for i in a.values():
    if i % 2 == 1:
        a1 += 1
    elif i % 4 == 2:
        a2 += 2
if h % 2 == 1:
    if w % 2 == 1:
        b1 = 1
        b2 = h + w - 2
    else:
        b1 = 0
        b2 = w
else:
    if w % 2 == 1:
        b1 = 0
        b2 = h
    else:
        b1 = 0
        b2 = 0
if a1 > b1 or a2 > b2:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9232
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int prev = 0;
        boolean[] isDiffDirection = new boolean[n];
        for(int i = 0; i < n; i++) {
            char c = s.charAt(i);
            isDiffDirection[i] = c == 'E';
        }
        for(int i = 1; i < n; i++) {
            if(isDiffDirection[i]) prev++;
        }
        int min = prev;
        for(int i = 1; i < n; i++) {
            int count = prev;
            if(s.charAt(i) == 'E') count--;
            if(s.charAt(i-1) == 'W') count++;
            prev = count;
            min =  Math.min(min, count);
        }
        System.out.println(min);
    }
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int n,x,y;
    cin >> n >> x >> y;
    map<int,int> ans;
    rep(i,n-1) ans[i]++;

    for(int i=1;i<n;i++){
        for(int k=i+1;k<=n;k++){
            int s = k-i;
            if(i<=x&&k<=y){
                s = min(s,x-i+1+y-k);
            }else if(i>=x&&k>=y){
                s = min(s,i-x+1+k-y);
            }else if(i<x&&k>y){
                s = s - (y-x-1) ;
            }else{
                s = min(s,i-x+1+y-k);
            }
            ans[s-1]++;
        }
    }
    
    for(int i=0;i<n-1;i++){
        ans[i]--;
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 384
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n=nxt(),m=nxt();
	rep(a,0,m)
	{
		ll b=nxt();
		n-=b;
	}
	n=max(n,-1*1LL);
	cout<<n<<endl;
	printclock;
	return 0;
}


Measured memory_bytes: 3808
# input
N = int(input())
S = input()

# process
ans = S.count('R')*S.count('G')*S.count('B')
for i in range(N):
    for j in range(N):
        if i-j<0 or i+j >= N:
            break
        x = S[i-j]
        y = S[i]
        z = S[i+j]

        if x!= y and x != z and y != z:
            ans -= 1
            
# output
print(ans)


Measured memory_bytes: 9144
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

void solve(){
    lli n; cin>>n; 
    float d = (2*22*n)/7.0;
    cout<<d<<'\n';
    return;
}
int main(){
    fastIO;
    lli t = 1; 
    // cin>>t; p = t;
    NA(i,0,t) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3808
//03, 06, 2018, 09:01:09 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;

int digits(int n){
    int s = 0;

    while(n){
        s += n % 10;
        n /= 10;
    }

    return s;
}

int main(){
    int n;

    cin >> n;

    int best = int(1e9);

    for(int a = 1 ; a < n ; a++){
        int sa = digits(a);
        int sb = digits(n - a);
        
        best = min(best, sa + sb);
    }

    cout << best << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int in;
	vb b(30,true);
	rep(i,28){
		cin>>in;in--;
		b[in]=false;
	}
	rep(i,30){
		if(b[i])cout<<i+1<<endl;
	}
}



Measured memory_bytes: 3200
t = input()
lis = list(t)

for i in range(len(t)):
    if i==0 and lis[i]=="?":
        lis[i]="D"
    if i>=1 and lis[i]=="?" and lis[i-1]=="D":
        lis[i]="D"
    if i>=1 and lis[i]=="?" and lis[i-1]=="P":
        lis[i]="D"
    if i>=1 and lis[i]=="?" and lis[i-1]=="?":
        lis[i]="D"

print(''.join(lis))


Measured memory_bytes: 10812
#include <stdio.h>

int gcd(int p,int q){while(q){int t=p%q;p=q;q=t;}return p;}

int main(){
	int k;
	scanf("%d",&k);
	int ans=0;
	for(int a=1;a<=k;a++)for(int b=1;b<=k;b++){
		int temp=gcd(a,b);
		for(int c=1;c<=k;c++){
			ans+=gcd(temp,c);
		}
	}
	printf("%d",ans);
}

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

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

int n;
vector<int> d[31];
int memo[31][50];
bool done[31][50];

void init(void) {
  rep(i,31) d[i].clear();
}

void init_dp(void) {
  rep(i,31) {
    rep(j,n) {
      done[i][j] = false;
    }
  }
}

int rec(int i, int j) {
  if (i == 0) {
    done [i][j] = true;
    return memo[i][j] = 1ll<<j;
  }
  if (done[i][j]) return memo[i][j];
  bool flag = false;
  for (auto v : d[i]) {
    if (v == j) flag = true;
  }

  int ret = 0;
  if (flag) {
    for (auto v : d[i]) {
      ret |= rec(i - 1, v);
    }
  } else {
    ret = rec(i - 1, j);
  }
  done[i][j] = true;
  return memo[i][j] = ret;
}

void solve(void) {
  init_dp();
  rep(j,n) rec(30, j);

  rep(i,31) {
    rep(j,n) {
      if (memo[i][j] == ((1ll << n)-1)) {
        cout << i << endl;
        return;
      }
    }
  }

  cout << -1 << endl;
}
signed main(void) {
  while (true) {
    init();
    cin >> n;
    if (n == 0) break;
    rep(i, n) {
      int f;
      cin >> f;
      rep(j, f) {
        int tmp;
        cin >> tmp;
        d[tmp].push_back(i);
      }
    }
    solve();
  }
}




Measured memory_bytes: 3116
A, B = map(int, input().split())
S = input()

#A文字目までが数字か
check_1 = S[:A].isdecimal()
check_2 = S[A+1:].isdecimal()
check_3 = (S[A:A+1] == "-")

if check_1 & check_2 & check_3:
    print("Yes")
else:
    print("No")

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

using namespace std;

const int MOD = 1e9 + 7;

int a[25][25], n;
long long dp[(1 << 21) + 5];

long long solve(int mask) {
    if (dp[mask] != -1) return dp[mask];
    if (mask == 0) return dp[mask] = 1;

    int id = __builtin_popcount(mask) - 1;
    long long tot = 0;

    for (int i = 0; i < n; i++) {
        if (a[id][i] && (mask & (1 << i))) tot = (tot + solve(mask ^ (1 << i))) % MOD;
    }

    return dp[mask] = tot;
}

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

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

    memset(dp, -1, sizeof(dp));

    printf("%lld\n", solve((1 << n) - 1));
}


Measured memory_bytes: 16640
import java.util.Scanner;
import java.util.Stack;

public class Main {
  static int[][] numbers;
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner in = new Scanner(System.in);
    long x= in.nextLong();
    long k = in.nextLong();
    long d = in.nextLong();

    x = Math.abs(x);
    if(x>0 && (x/d)>=k) {
       long q = x/d;
       x = x-(k)*d;

    } else {
      long y = x/d;
      x =x -(y)*d;
      k -=y;
      if(k%2==0)
        x= Math.abs(x);
      else
        x = Math.min(Math.abs(x-d),Math.abs(x+d));
    }

    System.out.println(x);     
  }
  
  
}


Measured memory_bytes: 35680
import math

def resolve():
    N, K= map(int, input().split())
    A_list = []
    ans_list = []

    for i in range(K):
        d = int(input())
        a_list = list(map(int, input().split()))
        A_list.append(a_list)
        for j in a_list:
            ans_list.append(j)

    print(N - len(set(ans_list)))


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9136
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int main()
{
	vector<int> v;
	REP(i, 5)
	{
		int tmp;
		cin >> tmp;
		v.push_back(tmp);
	}
	sort(v.begin(), v.end(), greater<int>());
	REP(i, 4) cout << v[i]<<" ";
	cout << v[4] << endl;
	return 0;
}

Measured memory_bytes: 1216
import java.util.*;

public class Main{

    int[] p;
    int MAX = 1000000;

    void solve(){
        Scanner sc = new Scanner(System.in);

        p = new int[MAX];
        for(int i=2; i<p.length; i++)p[i] = 1;
        for(int i=2; i<Math.sqrt(MAX)+1; i++){
            for(int j=i*2; j<MAX; j+=i){
                p[j] = 0;
            }
        }

        while(true){
            int n = sc.nextInt();
            int P = sc.nextInt();
            if(n==-1 && P==-1) break;

            int[] array = new int[10000];
            Arrays.fill(array,Integer.MAX_VALUE);
            int idx = 0;
            for(int i=n+1; i<n+300; i++){
                if(p[i]==0) continue;
                for(int j=i; j<n+300; j++){
                    if(p[j]==0) continue;
                    array[idx] = i+j;
                    idx++;
                }
            }

            Arrays.sort(array);

            System.out.println(array[P-1]);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 16000
#include <stdio.h>
#include <stdlib.h>

#define BUF 32

int main(void) {
    int num[BUF] = {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};

    int point;
    scanf("%d", &point);
    printf("%d\n", num[point - 1]);
    return 0;
}

Measured memory_bytes: 128
n, m = map(int, input().split())
tree = [[] for _i in range(m+n+1)]
for i in range(n):
    x = list(map(int, input().split()))
    tree[i].extend([i+n for i in x[1:]])
    for j in x[1:]:
        tree[j+n].append(i)

from collections import deque
q = deque([1])
visit = [0 for _i in range(m+n+2)]
visit[1] = 1
while q:
    p = q.pop()
    for j in tree[p]:
        if visit[j]==0:
            visit[j] = 1
            q.appendleft(j)
if sum(visit[:n]) == n:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 79180
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int a,b,c,d,k;
	cin>>a>>b>>c>>d>>k;
	cout<<(c*60+d - (a*60+b)-k);
}

Measured memory_bytes: 3640
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const newNode = (id, arr) => {
    return {
        id: id,
        children: [...arr],
        parentNode: -1,
        depth: null
    };
};

const nodeToString = node => {
    const type = node.parentNode === -1 ? 'root'
               : node.children.length > 0 ? 'internal node'
               : 'leaf';
    const arr = `[${node.children.join(', ')}]`;
    return `node ${node.id}: parent = ${node.parentNode}, depth = ${node.depth}, ${type}, ${arr}`;
};

const setDepth = tree => {
    const root = tree.filter(x => x.parentNode === -1)[0];
    const helper = (node, n) => {
        node.depth = n;
        node.children.forEach(x => {
            helper(tree[x], n+1);
        });
    };
    helper(root, 0);
};

const n = parseInt(line[0]);
const data = line.slice(1, n+1)
                 .map(x => x.split(' ').map(Number));

const tree = data.map(x => {
    const id = x[0];
    const children = x.slice(2);
    return newNode(id, children);
});

tree.sort((a, b) => a.id - b.id);
tree.forEach((x, _, arr) => {
    x.children.forEach(y => {
        arr[y].parentNode = x.id;
    });
});

setDepth(tree);

console.log(tree.map(x => nodeToString(x)).join('\n'));



Measured memory_bytes: 157816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,0,n) cin>>a[i];

    vector<ll> cnt(n+1,0);
    ll ans=1;
    rep(i,0,n){
        if(a[i]!=0) ans=(ans*(cnt[a[i]-1]-cnt[a[i]]))%MOD;
        else ans=(ans*(3-cnt[0]))%MOD;
        cnt[a[i]]++;
    }
    cout<<ans%MOD<<endl;


}

Measured memory_bytes: 1792
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll a, b, c, d, n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b >> c >> d >> n;
    b = min(b, 2 * a);
    c = min(c, 2 * b);
    d = min(d, 2 * c);
    cout << n / 2 * d + n % 2 * c << "\n";
    return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;
typedef long long ll;

ll vs[100000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lld", &vs[i]);
  }
  vector<ll> ls;
  sort(vs, vs + n);
  for(int i = n-1; i >= 1; --i) {
    if(vs[i] == vs[i-1]) {
      ls.push_back(vs[i]);
      --i;
      if(ls.size() >= 2u) {
        break;
      }
    }
  }
  
  printf("%lld\n", ls.size() >= 2u ? ls[0] * ls[1] : 0);
  return 0;
}


Measured memory_bytes: 1024
import Control.Monad
import Data.List.Split
import Text.Printf
main = do
  s <- getContents
  let v = map (map (read::String->Double) . (splitOn ",")) . lines $ s
  let w = filter (/="") . map aux $ v
  mapM_ putStrLn w 

aux::[Double] -> String
aux f = let num=f!!0
            w = f!!1
            h = f!!2
            in
         if w/h/h >= 25.0 then printf "%.0f" num else ""

Measured memory_bytes: 4308
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll h, n;
int main() {
	cin >> h >> n;
	vector<ll> s(n);
	REP(i, n)cin >> s[i];
	REP(i, n) h -= s[i];
	cout << (h <= 0 ? "Yes" : "No") << endl;

}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#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,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


int main(){
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    
    rep(j,H){
        rep(i,W){
            if (i <= A-1 && j <= B-1) cout << 1;
            else if( i>A-1&&j>B-1) cout << 1;
            else cout << 0;
            
    }
        cout << endl;
    }
    rn 0;
}


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

using namespace std;

int main()
{
	string s;

	cin >> s;

	int ans = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		for (int j = i; j < s.size(); ++j)
		{
			bool isACGT = true;
			for (int k = i; k <= j; ++k)
			{
				if (!(s[k] == 'A' || s[k] == 'C' || s[k] == 'G' || s[k] == 'T'))
				{
					isACGT = false;
				}
			}
			if (isACGT)
			{
				ans = max(ans, j - i + 1);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long ll;

ll o[65],z[65];

bool checkbit(ll N,int pos)
{
    return (bool)(N & (1LL<<pos));
}

ll mulMod(ll a,ll b,ll M)
{
    return ((a%M)*(b%M))%M;
}

ll addMod(ll a,ll b,ll M)
{
    return ((a%M)+(b%M))%M;
}

int main()
{
    //freopen("in.txt","r", stdin);
    //freopen("out.txt","w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);

    ll n,x,m = 1e9+7;

    cin>>n;

    for(int i=0; i<n; i++)
    {
        cin>>x;
        for(int j=0; j<=61; j++)
        {
            if(checkbit(x,j))   o[j]++;
            else                z[j]++;
        }
    }

    ll ans = 0;

    for(ll i=0; i<=61; i++)
        ans = (ans+((((o[i]*z[i])%m)*((1LL<<i)%m))%m))%m;

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
int N;
ll A[100010];

int check(ll n) {
	ll remaining = A[0] - n;
	ll now = n;
	for (int i = 1; i < N; i++) {
		now = A[i] - now;
	}
	if (remaining == now) return 0;
	if (remaining < now) return 1;
	return -1;
}

void solve() {

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	ll lower = 0;
	ll upper = A[0];
	ll ans;
	while (lower <= upper) {
		ll mid = (lower + upper) / 2;
		int ok = check(mid);
		if (ok == 0) {
			ans = mid;
			break;
		}
		if (ok == 1) upper = mid - 1;
		else lower = mid + 1;
	}

	for (int i = 0; i < N - 1; i++) {
		cout << 2 * (A[i] - ans) << " ";
		ans = A[i + 1] - ans;
	}
	cout << 2 * (A[N - 1] - ans) << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}

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

int main(){
	cout.precision(13);
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	char m[256];
	for(char c = 'a'; c <= 'z'; ++c){
		m[c] = c;
	}
	m['b'] = 'd';
	m['d'] = 'b';
	m['p'] = 'q';
	m['q'] = 'p';
	string t = s;
	reverse(t.begin(), t.end());
	for(int i = 0;i < t.length(); ++i){
		t[i] = m[t[i]];
	}

	cout << (s == t?"Yes":"No") << '\n';
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

// coef[]
// aX + bY = c
// ^0   ^1   ^2
// dX + eY = f
// ^3   ^4   ^5
// answer[]
// X: answer[0]
// Y: answer[1]
// form_revA[4]
// [ p  q ]
//   ^0 ^1
// [ r  s ]
//   ^2 ^3
int alg ( int* coef, float* answer )
{
    float det, form_revA[4] = { 0 };

    if ( (det = coef[0] * coef[4] - coef[1] * coef[3]) == 0 )
        return -1;

    form_revA[0] = coef[4] / det;
    form_revA[1] = - ( coef[1] / det );
    form_revA[2] = - ( coef[3] / det );
    form_revA[3] = coef[0] / det;

    answer[0] = coef[2] * form_revA[0] + coef[5] * form_revA[1];
    answer[1] = coef[2] * form_revA[2] + coef[5] * form_revA[3];

    return 0;
}

int main ( void )
{
    int coef[6] = { 0 };
    float answer[2] = { 0.0 };

    while ( scanf("%d %d %d %d %d %d",
                &coef[0], &coef[1], &coef[2], &coef[3], &coef[4], &coef[5] )
            != EOF )
    {
        if ( alg( coef, answer ) < 0 )
            puts( "NO ANSWER" );
        else
            printf("%.3f %.3f\n", answer[0], answer[1] );
    }

    return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

int main() {
	
	ll n, x;
	cin >> n >> x;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	
	ll ans = 0;
	if(a[0] > x){
		ans = a[0] - x;
		a[0] = x;
	}
	REP(i, 1, n){
		if(a[i] + a[i - 1] > x){
			ll tmp = a[i] + a[i-1] - x;
			ans += tmp;
			a[i] -= tmp;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

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

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

    for (int i = 0; i <= N / 4; i++) {
        if ((N - i * 4) % 7 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
fn main() {
    let (n, a, b) = input();
    println!("{}", solve(n, a, b));
}

fn input() -> (usize, usize, usize) {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();
    (n, a, b)
}

fn solve(n: usize, a: usize, b: usize) -> usize {
    let c = (n / (a+b));
    let d = n - c * (a + b);
    if d < a {
        return a * c + d
    }
    a * (c + 1)
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
 
const int N = 5e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
 
    int n, K;
    cin >> n >> K;
    vector<int> v(n+1, 1e9), dp(n+1, 0);
    cin >> v[1];
    dp[1] = 0;
    for(int j = 2; j <= n; j++){
        cin >> v[j];
        dp[j] = 1e9 + 7;
        for(int k = 1; k <= K; k++){
            if(j-k >= 0) dp[j] = min(dp[j], dp[j-k]+abs(v[j]-v[j-k]));
        }
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1024
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

class Edge {
    int from, to;
    bool isBridge;
    this(int from, int to) {
        this.from = from;
        this.to = to;
    }
    override string toString() {
        return [from, to, isBridge].to!string;
    }
}
class Graph {
    Edge[][] G;
    int V;
    this(int V) {
        this.V = V;
        G = new Edge[][V];
    }
    void addEdge(int from, int to) {
        G[from] ~= new Edge(from, to);
        G[to] ~= new Edge(to, from);
    }
}

const int INF = int.max/4;
void solve() {
    int N, M; scanf("%d %d\n", &N, &M);
    auto W = stdin.readln.chomp.split(" ").map!(to!int).array;
    auto graph = new Graph(N);
    foreach (i; 0 .. M) {
        int u, v; scanf("%d %d\n", &u, &v); u--; v--;
        graph.addEdge(u, v);
    }
    auto g = graph.G;

    auto visited = new bool[N];
    Tuple!(bool, int, int) dfs(int v, int prev) {
        visited[v] = true;
        int ans = W[v];
        int diff_max = 0;
        bool can_ret = false;
        foreach (e; g[v]) {
            if (e.to == prev) continue;
            if (visited[e.to]) {
                can_ret = true;
                continue;
            }
            auto r = dfs(e.to, v);
            if (r[0]) can_ret = true;
            ans += max(0, r[1]);
            diff_max = max(diff_max, r[2] - max(0, r[1]));
        }
        //log([v, prev, can_ret, can_ret ? ans: -INF, ans + diff_max]);
        return tuple( can_ret, (can_ret ? ans : -INF), ans + diff_max);
    }
    dfs(0, -1)[2].writeln;
}


import core.memory;
alias base_t = long;
const base_t STACK_SIZE = (base_t.sizeof) * (1<<24);
__gshared void* stack;
__gshared base_t org_esp;
__gshared base_t esp;
void main() {
    GC.disable();
    stack = GC.malloc(STACK_SIZE);
    esp = cast(base_t)(stack) + STACK_SIZE - 1;
    asm {
        mov org_esp, RSP;
        mov RSP, esp;
    }

    solve();

    asm {
        mov RSP, org_esp;
    }
}

Measured memory_bytes: 33764
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int c=a;
	int b=0;
	for(int i=0;i<=10;i++) {
		b+=a%10;
		a/=10;
	}
	System.out.println(c%b==0?"Yes":"No");
}
}

Measured memory_bytes: 22868
#include<iostream>
#include<vector>
using namespace std;
int main(int argc, char const *argv[])
{
   int n;
   cin >> n;
   vector<int> a(n), b(n), c(n-1);
   for (int i = 0; i < n; i++)
   {
      cin >> a[i];
      a[i] -= 1;
   }
   for (int i = 0; i < n; i++)
   {
      cin >> b[i];
   }
   for (int i = 0; i < n-1; i++)
   {
      cin >> c[i];
   }

   int ans = 0;
   for (int i = 0; i < n; i++)
   {
      ans += b[a[i]];

      if(i == 0 || a[i - 1] + 1 != a[i])
         continue;
      
      ans += c[a[i] - 1];
      
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
s = list(map(int, input()))
j = 1
r = 0
t = []
for i in range(n):
  if s[i] == j:
    r += 1
  else:
    t.append(r)
    r = 1
    j ^= 1
t.append(r)
if j == 0:
  t.append(0)
if k >= (len(t) - 1) // 2:
  print(sum(t))
else:
  result = sum(t[:2 * k + 1])
  j = sum(t[:2 * k + 1])
  i = 2
  while i + 2 * k < len(t):
    j += t[i + 2 * k - 1] + t[i + 2 * k] - (t[i - 2] + t[i - 1])
    result = max(result, j)
    i += 2
  print(result)


Measured memory_bytes: 5152
import math
import itertools
# math.sqrt(数値)

def calcDist(row1, row2):
    n_dist = 0
    for d in range(D):
        dist = abs(row1[d] - row2[d])
        n_dist += dist ** 2
    return n_dist

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

dimentions = []

for i in range(N):
    row = list(map(int, input().split()))
    dimentions.append(row)
    
dim_combinations = itertools.combinations(dimentions, 2)

all_dist = []

for pair in dim_combinations:
    n_dist = calcDist(pair[0], pair[1])
    all_dist.append(math.sqrt(n_dist))

cnt = 0
for dist in all_dist:
    if dist.is_integer():
        cnt += 1
        
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200005;
int n;
int f[N],MaxD[N],FaD[N],Lim[N],Min[N],Max[N],tot[N];
vector <int> e[N];
void dfs(int x,int pre){
	MaxD[x]=0;
	tot[x]=f[x];
	for (auto y : e[x])
		if (y!=pre){
			dfs(y,x);
			MaxD[x]=max(MaxD[x],MaxD[y]+1);
			tot[x]+=tot[y];
		}
}
multiset <int> S;
LL ans=0;
void getlim(int x,int pre){
	Lim[x]=max(FaD[x],MaxD[x]);
	S.clear();
	S.insert(FaD[x]);
	for (auto y : e[x])
		if (y!=pre)
			S.insert(MaxD[y]+1);
	for (auto y : e[x])
		if (y!=pre){
			S.erase(S.find(MaxD[y]+1));
			FaD[y]=(*--S.end())+1;
			S.insert(MaxD[y]+1);
		}
	for (auto y : e[x])
		if (y!=pre)
			getlim(y,x);
}
void solve(int x,int pre){
	for (auto y : e[x])
		if (y!=pre){
			solve(y,x);
			Min[y]=min(Min[y],MaxD[y]+1);
			Min[x]=min(Min[x],FaD[y]);
			if (!f[y]&&tot[1]-tot[y]>0)
				Max[y]=min(Max[y],FaD[y]);
			if (!f[x]&&tot[y]>0)
				Max[x]=min(Max[x],MaxD[y]+1);
		}
}
int main(){
	scanf("%d",&n);
	ans=1;
	for (int i=1;i<=n;i++)
		e[i].clear();
	for (int i=1,a,b;i<n;i++){
		scanf("%d%d",&a,&b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	for (int i=1;i<=n;i++)
		scanf("%1d",&f[i]);
	dfs(1,0);
	getlim(1,0);
	for (int i=1;i<=n;i++)
		Min[i]=Lim[i]-1,Max[i]=f[i]?0:1e9;
	solve(1,0);
	for (int i=1;i<=n;i++)
		ans+=max(Min[i]-Max[i]+1,0);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 30976
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Double R;
  cin>>R;

  Double ans = 2 * R * PI;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3768
N,K = map(int, input().split())
if N > K and N//K>2:
	a = N//K
	N= N-K*(a-2)

while N>0:
	T = N
	N = abs(N-K)
	if N >T:
		break

print(N if N==0 else min(N,T) )

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

using namespace std;

int main()
{
    char str[100];
    scanf("%s", &str);

    int len = strlen(str);
    int c = 0;
    int i = 0;
    while(i < len) {
        if(count(str, str + len, str[i]) % 2 == 0) {
            c++;

            if(c == len) {
                printf("Yes");
            }
        } else {
            printf("No");
            break;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 3824
#include<stdio.h>
#include<math.h>
int main(){
  double a,b,c;

  scanf("%lf %lf %lf",&a,&b,&c);
  c/=180;
  c*= acos(-1);
  printf("%f\n%f\n%f\n",(double)a*b*0.5*sin(c),a+b+sqrt((double)a*a+b*b - 2*a*b*co\
s(c)),a*b*sin(c)/a);
  return 0;
}



Measured memory_bytes: 2148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 085_A
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		String S = sc.nextLine();
		// Scannerクラスのインスタンスをクローズ
		sc.close();

		System.out.println("2018"+S.substring(4));
	}
}


Measured memory_bytes: 38488
#include <iostream>

int cutBySeven(int x)
{
  if (x > 7){
    return 7;
  }else{
    return x;
  }
}

int main()
{
  // データ準備
  int a, b, c;

  std::cin >> a >> b >> c;

  // 1週間ログインするともらえるコイン
  int coinPerWeek = 7*a+b;

  // 最低何週間のログインが必要か
  int minimumWeek = c/coinPerWeek;

  // minimumWeek 週間のログインで足りない分のコイン
  int luck = c%coinPerWeek;

  // luck 分のコインを集めるのに必要な日数
  int daysForLuck = cutBySeven((luck%a==0) ? luck/a : luck/a+1);

  // 出力
  std::cout << minimumWeek*7+daysForLuck << '\n';
}



Measured memory_bytes: 3116
n, c = map(int, input().split())
X = [0 for _ in range(n)]
V = [0 for _ in range(n)]
right = [0 for _ in range(n)]
left = [0 for _ in range(n)]
rl = [0 for _ in range(n)]
lr = [0 for _ in range(n)]
rlm = [0 for _ in range(n)]
lrm = [0 for _ in range(n)]

calsum = 0
for i in range(n):
    x, v = map(int, input().split())
    X[i] = x
    V[i] = v
    calsum += v
    right[i] = calsum-x
    rl[i] = calsum-2*x

calsum = 0
for i in range(n):
    calsum += V[n-i-1]
    left[i] = calsum - (c-X[n-i-1])
    lr[i] = calsum - 2*(c-X[n-i-1])

m = 0
for i in range(0, n-1):
    m = max(m, left[i])
    rlm[i] = m + rl[n-i-2]

m = 0
for i in range(0, n-1):
    m = max(m, right[i])
    lrm[i] = m + lr[n-i-2]

print(max(0, max(right), max(left), max(rlm), max(lrm)))


Measured memory_bytes: 36428
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

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

using namespace std;
int n,m;

int main()
{
    int a,b;
    cin >> a >> b;
    int c = b * 2 - a;
    cout << c << endl;
    return 0;
}


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

int main() {
	int x = 0;
	int n = 0;
	std::cin >> x >> n;
	std::vector<decltype(x)> vect(n);
	bool vect_contains_x = false;
	for (auto& elem : vect) {
		std::cin >> elem;
		if (elem == x) {
			vect_contains_x = true;
		}
	}
	int num = 0;
	if (!vect_contains_x) {
		num = x;
	}
	else {
		std::sort(vect.begin(), vect.end());
		while (1) {
			static int i = 1;
			if (std::binary_search(vect.begin(), vect.end(), x - i) == false) {
				num = x - i;
				break;
			}
			else if (std::binary_search(vect.begin(), vect.end(), x + i) == false) {
				num = x + i;
				break;
			}
			else {
				i += 1;
			}
		}
	}
	std::cout << num << "\n";
	return 0;
}

Measured memory_bytes: 3156