akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define exit(x)     cout<<x<<"\n",return
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;
using namespace std;


ll dp[10001][101][2];
ll dv;
// TO SEE STATES SEE SOLVE FUNC
string s;
ll solve(int pos,int mo,int tight)
{
    if(pos==s.size())
        {
          
          if(mo==0)
          {
            return 1;
          }                         
          return 0;
        }
    if(dp[pos][mo][tight]!=-1)
    {
      return dp[pos][mo][tight];
    }
    int d = s[pos] - '0';
    ll sum=0;
    for (int i = 0; i < 10; ++i)
    {
      if(!tight and i>d) break;     
       sum =(sum + solve(pos + 1,(mo + i)%dv,tight | (i<d) ))%mod;
    }
  
       return dp[pos][mo][tight] = sum;

}


signed main(){
  
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      
      cin>>s>>dv;
      memset(dp,-1,sizeof(dp));
    
      ll ans1=solve(0,0,0);
      ans1=(ans1 -1 + mod)%mod;
      cout<<ans1<<endl;
      
      return 0;
    }


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

typedef long long int ll;

int main(){
	ll N, ans=0, temp;
	cin>>N;
	vector <ll> a, b;

	for(int i=0; i<N-1; i++){
		cin>>temp;
		b.push_back(temp);
	}
	ans+=b[0];
	for(int i=0; i<N-2; i++){
		ans+= min(b[i], b[i+1]);
	}
	ans+=b[N-2];
	cout<<ans;
}

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

namespace CSharpSample01
{
    
    class Program
    {

        static List<string> str;

        static void Me(int k, string strer)
        {
            if(k == 3)
            {
                str.Add(strer);
                return;
            }

            Me(k + 1, strer + "+");

            Me(k + 1, strer + "-");

        }


        static void Main(string[] args) 
        {
            str = new List<string>();

            Me(0, "");

            string s = Console.ReadLine();

            var data = new int[4];
            for(int i = 0; i < s.Length; i++)
            {
                data[i] = int.Parse(s[i].ToString());
            }

            
            for(int i = 0; i < str.Count; i++)
            {
                string ss = str[i];
                int sum = data[0];
                for(int j = 0; j < ss.Length; j++)
                {
                    if(ss[j] == '+')
                    {
                        sum += data[j + 1];
                    }
                    else
                    {
                        sum -= data[j + 1];
                    }
                }
                //Console.WriteLine($"{ss} : {sum}");
                if(sum == 7)
                {
                    Console.Write(data[0]);
                    for(int j = 0; j < 3; j++)
                    {
                        Console.Write($"{ss[j]}{data[j + 1]}");
                    }
                    Console.WriteLine("=7");
                    return;
                }
            }



        }
    }
}


Measured memory_bytes: 13268
import time
start=time.time()
k=int(input())
if k%2==0:exit(print(-1))
ans=0
x=k
for i in range(10**9):
  while x%10!=7:
    x+=k
    if time.time()-start>=1.9:exit(print(-1))
  x//=10
  if x==0:exit(print(i+1))

Measured memory_bytes: 67596
# ABC095C - Half and Half
def main():
    a, b, c, x, y = list(map(int, input().rstrip().split()))
    ans = min(
        c * 2 * max(x, y),
        a * x + b * y,
        c * 2 * y + a * max(0, x - y),
        c * 2 * x + b * max(0, y - x),
    )
    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector L(N, 0);
  for (int &l : L) cin >> l;

  int ans = INT_MAX;
  for (int bit = 0; bit < pow(4, N); bit++) {
    int cost = 0, a = 0, b = 0, c = 0;
    for (int i = 0, dig = 1; i < N; i++, dig *= 4) {
      int tmp = bit / dig % 4;
      if (tmp == 1) cost += (a) ? 10 : 0, a += L.at(i);
      if (tmp == 2) cost += (b) ? 10 : 0, b += L.at(i);
      if (tmp == 3) cost += (c) ? 10 : 0, c += L.at(i);
    }
    if (!a || !b || !c) continue;
    cost += abs(A - a) + abs(B - b) + abs(C - c);
    ans = min(ans, cost);
  }
  cout << ans << "\n";
}

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

int main() {
	char s;
	int k = 0;
	for(int i = 0;i < 4;i++)
	{
		cin >> s;
		if(s == '+')
		{
			k++;
		}
		else
		{
			k--;
		}
	}
    cout << k << endl;
	return 0;
}


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

bool solve(int a) {
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i * j == a) return 1;
    }
  }
  return 0;
}

int main() {
  int a;
  cin >> a;
  if (solve(a)) cout << "Yes\n";
  else cout << "No\n";
}

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

int main(){
    int n, jo, ge, ans = 0;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(), l.end());

    for(int i = 0; i < n - 2; i++){
        for(int j = i + 1; j < n - 1; j++){
            if (l[i] + l[j] > l[n - 1]) { ans += n - j - 1; }
			else if (l[i] + l[j] <= l[j + 1]) { }
			else {
				jo = n - 1;
				ge = j + 1;
 
				while (jo != ge + 1) {
					if (l[i] + l[j] > l[(jo + ge) / 2]) { ge = (jo + ge) / 2; }
					else { jo = (jo + ge) / 2; }
				}
				ans = ans + ge - j;
			}
	    }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define rep(i,a,b) for(i=a;i<=b;i++)
#define rrep(i,a,b) for(i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979311599796346854418516159057617187500
const ll N=1e5+5,mod=1000000007;
ll f(ll n)
{
	ll ans=0;
	while(n)
	{
		n/=10;
		ans++;
	}
	return ans;
}
signed main()
{
    fast;
    ll pro=1,temp,t,n,m,k,i,j,l,r,mid,x,y,z,rem,carry=0,ind,ans=0,mx=-llinf,mn=llinf,cnt=0,curr=0,prev,sum=0,flag=1,i1=-1,i2=-1;
    cin>>n;
    ll a[n+1];
    a[0]=0;
    rep(i,1,n)
    {
    	cin>>a[i];
    	a[i]=min(a[i],max(a[i-1],a[i]-1));
    	
    	if(a[i]<a[i-1])
    	{
    		return cout<<"No",0;
    	}
    }
    cout<<"Yes";
	return 0;
} 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0,b=0;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    b=b+pow(a.at(i),2);
  }
  for(int i=1;i<=100;i++){
    for(int j=0;j<n;j++){
      c=c+pow((i-a.at(j)),2);
    }
    b=min(b,c);
    c=0;
  }    
  cout <<b;
}

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

using std::min;
using std::vector;
using std::cin;
using std::cout;
using std::endl;


const static int neutral = 1000000000;
		

struct Node {
	size_t l;
	size_t r;
	Node* left;
	Node* right;
	int minimum;
	int add;

	Node (size_t l, size_t r, int minimum = neutral) {
		this->l = l;
		this->r = r;
		this->left = nullptr;
		this->right = nullptr;
		this->minimum = minimum;
		this->add = 0;
	}

	void push ();
} *root;

void Node::push () {
	if (left)
		left->add += add;
	
	if (right)
		right->add += add;

	minimum += add;
	add = 0;
}


/////////////////////////////////////////////////


class SegmentTree {
	private:

		int build (Node*, const vector<int>&);
	
	public:
		SegmentTree (const vector<int>&);
		int RMQ (size_t, size_t, Node*);
		void RAQ (size_t, size_t, int, Node*);
};

SegmentTree::SegmentTree (const vector<int> &array) {
	root = new Node(0, array.size() - 1);
	build(root, array);
}

int SegmentTree::build (Node *node, const vector<int> &array) {
	if (node->l != node->r) {
		size_t half = node->l + (node->r - node->l) / 2;
		node->left = new Node(node->l, half);
		node->right = new Node(half + 1, node->r);
		int left_min = build(node->left, array);
		int right_min = build(node->right, array);
		return node->minimum = min(left_min, right_min);
	}
	
	else {
		node->left = nullptr;
		node->right = nullptr;
		return node->minimum = array[node->l];
	}
}

int SegmentTree::RMQ (size_t l, size_t r, Node *node = nullptr) {
	if (!node)
		node = root;

	node->push();

	if (l <= node->l && node->r <= r)
		return node->minimum;

	if (node->r < l || r < node->l)
		return neutral;

	return min<int>(RMQ(l, r, node->left), RMQ(l, r, node->right));
}

void SegmentTree::RAQ (size_t l, size_t r, int add, Node *node = nullptr) {
	if (!node)
		node = root;

	node->push();

	if (l <= node->l && node->r <= r) {
		node->add += add;
		node->push();
		return;
	}

	else if (node->r < l || r < node->l)
		return;

	else {
		RAQ(l, r, add, node->left);
		RAQ(l, r, add, node->right);
		node->minimum = min<int>(node->left->minimum, node->right->minimum);
	}
}


/////////////////////////////////////////////////


int main () {
	int n, q;
	cin >> n >> q;
	vector<int> array(n, 0);

	SegmentTree segmentTree(array);

	for (int i = 0; i < q; i ++) {
		int type;
		cin >> type;

		if (type == 0) {
			size_t l, r;
			int add;
			cin >> l >> r >> add;
			segmentTree.RAQ(l, r, add);
		}

		else {
			size_t l, r;
			cin >> l >> r;
			cout << segmentTree.RMQ(l, r) << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 12600
s = gets.strip

words = ['dream','dreamer','erase','eraser']

until s.empty? do
    reduced = false
    words.map do |w|
        if s[-w.size, w.size] == w
            s = s[0..-w.size-1]
            reduced = true
            break
        end
    end

    unless reduced
        puts 'NO'
        exit 0
    end
end

puts 'YES'

Measured memory_bytes: 92860
x, y, z, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

d = [e1+e2 for e1 in a for e2 in b]
d.sort(reverse=True)
d = d[:k]

e = [e1+e2 for e1 in d for e2 in c]    
e.sort(reverse=True)

for i in range(k):
  print(e[i])

Measured memory_bytes: 136284
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int H = int.Parse(input[0]);
    for (int i = 0; i < H; i++) {
      string s = Console.ReadLine();
      Console.WriteLine(s);
      Console.WriteLine(s);
    }
  }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll h,n,i,j;
    cin>>h>>n;
    vector<int> a(n),b(n);
    for(i=0;i<n;i++) cin>>a[i]>>b[i];
    vector<ll> dp(10009, 1e9);
    dp[0] = 0;
    for(i=1;i<=h;i++)
    {
        for(j=0;j<n;j++)
        {
            ll cur_damage = a[j], cur_cost = b[j];
            if(cur_damage>=i) dp[i] = min(dp[i], cur_cost);
            else
            {
                dp[i] = min(dp[i], dp[i-cur_damage] + cur_cost);
            }
        }
    }
    cout<<dp[h];
}

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

using namespace std;

void change_fs(int* x, int* y)
{
	int temp;
	temp = *y;
	*y = *x;
	*x = temp;
}

int main()
{	
	int n, m;
	while(cin >> n >> m && (n != 0 || m != 0) )
	{
		vector< pair<int, int> > d(n);

		for(int i = 0; i < n; i++)
			cin >> d[i].first >> d[i].second;

		for(int i = 0; i < n; i++)
			change_fs(&d[i].first, &d[i].second);

		sort(d.begin(), d.end());
		reverse(d.begin(), d.end());

		for(int i = 0; i < n; i++)
			change_fs(&d[i].first, &d[i].second);

		int counter = 0;
		int sum = 0;

		for(int i = 0; i < n;i++)
		{
			sum += d[i].first*d[i].second;
		}

		while(m > 0)
		{
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < d[i].first; j++)
				{
					counter += d[i].second;
					m--;
					if(m == 0 || counter > sum)
						break;
				}
				if (m == 0 || counter > sum)
					break;
			}
			if (m == 0 || counter > sum)
					break;
		}

		
		if(sum -counter < 0)
			cout << 0 << endl;
		else
			cout << sum - counter << endl;

	}
	return 0;
}


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


int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test=1;
	
	while(test--)
	{
	    long long B,a,b,c=0,k,d=0,i,n,m,j,temp,ans;
	    
	    cin>>n>>m;
	    vector<string>vec(n);
	    for(i=0;i<n;i++)
	    cin>>vec.at(i);
	    for(i=0;i<n;i++)
	    {
	        cout<<vec[i]<<endl;
	        cout<<vec[i]<<endl;
	    }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int cnt=0,acnt=0,x,y,gx,gy,h,w,dir=0;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
string s,mp[50];
bool iswall(int x,int y){
	return mp[x][y]=='#';
}
void suc(int &it){
	it++;
	acnt++;
	if(acnt>10000000){
		cout<<-1<<endl;
		exit(0);
	}
}
void exe(int &it){
	cnt++;
	if(s[it]=='^') if(!iswall(x+dx[dir],y+dy[dir])) x+=dx[dir],y+=dy[dir];
	if(s[it]=='v') if(!iswall(x-dx[dir],y-dy[dir])) x-=dx[dir],y-=dy[dir];
	if(s[it]=='>') dir=(dir+1)%4;
	if(s[it]=='<') dir=(dir+3)%4;
	suc(it);
	if(x==gx&&y==gy){
		cout<<cnt<<endl;
		exit(0);
	}
//	cout<<x<<" "<<y<<endl;
}
bool jo(int &it){
	bool neg=false,ret=false;
	if(s[it]=='~') neg=true,suc(it);
	if(s[it]=='N') if(dir==0) ret=true;
	if(s[it]=='E') if(dir==1) ret=true;
	if(s[it]=='S') if(dir==2) ret=true;
	if(s[it]=='W') if(dir==3) ret=true;
	if(s[it]=='C') if(iswall(x+dx[dir],y+dy[dir])) ret=true;
	if(s[it]=='T') ret=true;
	if(neg) ret=!ret;
	suc(it);
	return ret;
}
void expr(int& it);
void pro(int& it){
	while(s[it]!='$'&&s[it]!=']'&&s[it]!='}'){
		expr(it);
	}
}
void expr(int& it){
	if(s[it]=='['){
		suc(it);
		if(jo(it)){
			pro(it);
			suc(it);
		}else{
			int ct=1;
			while(ct>0){
				if(s[it]==']') ct--;
				if(s[it]=='[') ct++;
				suc(it);
			}
		}
	}else if(s[it]=='{'){
		suc(it);
		int cit=it;
		while(jo(it)){
			pro(it);
			suc(it);
			it=cit;
		}
		int ct=1;
		while(ct>0){
			if(s[it]=='}') ct--;
			if(s[it]=='{') ct++;
			suc(it);
		}
	}else{
		exe(it);
	}
}
int main(){
	cin>>h>>w;
	rep(i,h) cin>>mp[i];
	rep(i,h) rep(j,w){
		if(mp[i][j]=='s') x=i,y=j;
		if(mp[i][j]=='g') gx=i,gy=j;
	}
	cin>>s;
	s+='$';
	int it=0;
	pro(it);
	cout<<-1<<endl;
}

Measured memory_bytes: 1236
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>
#include <complex>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }

ll sti(string s) {
	ll len = s.length();
	if (len < 1) return 0;
	return (s[len - 1] - '0') + 10 * (sti(s.substr(0, len - 1)));
}

/***
split by t
***/
vcs splitAll(string s, string t) {
	vcs r;
	for (int p = 0; (p = s.find(t)) != s.npos;) {
		r.pb(s.substr(0, p));
		s = s.substr(p + t.size());
	}
	r.pb(s);
	return r;
}


int vals[100][100];
int N;

int dp[2][100];

int solve() {
	minit(dp, -1);
	
	int nw = 0, nx = 1;
	dp[0][50] = vals[0][50];
	for_(i, 0, N) {
		nw = i%2; nx = (nw+1)%2;
		for_(j, 0, 100) {
			if (dp[nw][j]<0) continue;
			if (vals[i+1][j-1]>0) dp[nx][j-1] = max(dp[nx][j-1], dp[nw][j] + vals[i+1][j-1]);
			if (vals[i+1][j+1]>0) dp[nx][j+1] = max(dp[nx][j+1], dp[nw][j] + vals[i+1][j+1]);
		}
	}
	
	return dp[(N+1)%2][50];
}

int main() {
	minit(vals, -1);
	
	string in; int prev_len = 0;
	int i = 0, j = 50;
	while (1) {
		getline(cin, in);
		if (in=="") break;
		
		vcs input = splitAll(in, ",");
		
		int len = (int)input.sz;
		j = 51 - len;
		
		for_(k, 0, len) {
			vals[i][j] = sti(input[k]);
			j += 2;
		}
		
		i++;
	}
	
	N = i;
	
	cout << solve() << endl;
	
	return 0;
}

Measured memory_bytes: 1244
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(S):
    return (S[2] == S[3]) and (S[4] == S[5])


if __name__ == "__main__":

    S = input()
    ans = solv(S)

    if ans:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

void a()
{
    int n;
    cin >> n;
    string temp = to_string(n);
    if(temp[0] == '9')
    {
       cout << "Yes" << endl;
        return;
    }else if(temp[1] == '9')
    {
        cout << "Yes" << endl;
        return;
    }
    cout << "No" << endl;
}

void b()
{
    int n;
    cin >> n;
    vector<pair<int, int>> lr;
    for(int i = 0; i < n; i++)
    {
        int r, l;
        cin >> l >> r;
        lr.push_back(make_pair(l, r));
    }
    int result = 0;
    for(auto elem : lr)
    {
        result += (elem.second - elem.first) + 1;
    }
    cout << result << endl;
}

void c()
{
    int n;
    cin >> n;
    map<int, int> a;
    int result = 0;
    for(int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        if(a[temp] == 0)
        {
            a[temp] = 1;
            result++;
        }else{
            a[temp] = 0;
            result--;
        }
    }
    cout << result;
}

void d()
{
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> rv(r);
    for(int i = 0; i < r; i++)
    {
        int temp;
        cin >> temp;
        rv[i] = temp - 1;
    }
    vector<vector<long long int>> d(n);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(i == j)
            {
                d[i].push_back(0);
            }else{
                d[i].push_back(1 << 29);
            }
        }
    }
    for(int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        d[a - 1][b - 1] = c;
        d[b - 1][a - 1] = c;
    }
    //ワーシャルフロイド法
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            for(int k = 0; k < n; k++)
            {
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
    long long int result = 1 << 29;
    sort(rv.begin(), rv.end());
    do{
       long long int temp = 0;
        for(int i = 0; i < r - 1; i++)
        {
           temp += d[rv[i]][rv[i + 1]];
        }
        if(temp < result)
        {
            result = temp;
        }
    }while (next_permutation(rv.begin(), rv.end()));
    cout << result << endl;
}

int main() {
    d();
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define X 10000
int A[2000001],C[X],B[2000001];
int main()
{
  int j,n;
  
  scanf("%d",&n);
  for(j=1;j<n+1;j++){
    scanf("%d",&A[j]);
  }
 
  for(j=0;j<X;j++){
    C[j]=0;
  }
  
  for(j=1;j<n+1;j++){
    C[A[j]]+=1;
  }
  
  for(j=0;j<X;j++){
    C[j]+=C[j-1];
  }
  
  for(j=n+1;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]-=1;
  }
 
  for(j=1;j<n;j++){
    printf("%d ",B[j]);
  }
  
  printf("%d",B[j]);
  printf("\n");
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, lim;
int w[105], v[105];
int dp[105][305][105];
int ans;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> lim;
    rep(i, n) cin >> w[i] >> v[i];
    int b = w[0];
    rep(i, n) w[i] -= b;
    rep(i, n)rep(j, 305)rep(k, 102) {
        dp[i + 1][j][k] = dp[i][j][k];
        if (j - w[i] >= 0 && k - 1 >= 0) {
            dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j - w[i]][k - 1] + v[i]);
        }
    }
    rep(j, 305)rep(k, 102) {
        if (lim >= j + k * b) ans = max(ans, dp[n][j][k]);
    }
    cout << ans << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll X;
    cin >> X;

    ll res = 0;
    while(1){
    	if(res*(res+1)/2>=X){
    		cout << res << endl;
    		return 0;
    	}
    	res++;
    }
    return 0;
}

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

signed main()
{
    int n, red, ans;
    string c;
    
    cin >> n;
    cin >> c;
    
    red = 0;
    for(int i=0 ;i<n ;i++ ){
        if(c[i] == 'R'){
            red ++;
        }
    }

    ans = 0;    
    for(int i=0 ;i<red ;i++ ){
        if(c[i] == 'W'){
            ans ++;
        }
    }
    
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 3716
import java.util.*;

public class Main {

    private static final int INF = 1_000_000_000;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int M = sc.nextInt();
        int[] rowCnt = new int[H];
        int[] colCnt = new int[W];
        int[] HH = new int[M];
        int[] WW = new int[M];
        for (int i = 0; i < M; i++) {
            int h = sc.nextInt()-1;
            int w = sc.nextInt()-1;
            rowCnt[h]++;
            colCnt[w]++;
            HH[i] = h;
            WW[i] = w;
        }
        
        int maxRowCnt = 0;
        for (int i = 0; i < H; i++) {
            maxRowCnt = Math.max(maxRowCnt, rowCnt[i]);
        }
        int mr = 0;
        for (int i = 0; i < H; i++) {
            if (rowCnt[i] == maxRowCnt) mr++;
        }


        int maxColCnt = 0;
        for (int i = 0; i < W; i++) {
            maxColCnt = Math.max(maxColCnt, colCnt[i]);
        }
        int mc = 0;
        for (int i = 0; i < W; i++) {
            if (colCnt[i] == maxColCnt) mc++;
        }

        long mm = 0;
        for (int i = 0; i < M; i++) {
            if (rowCnt[HH[i]] + colCnt[WW[i]] == maxRowCnt + maxColCnt) mm++;
        }

        System.out.println(mm == (long)mc*mr ? maxRowCnt+maxColCnt-1 : maxRowCnt+maxColCnt);
    }
}


Measured memory_bytes: 64248
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string a[105],b[105];
    int n,m,c[105],d[105],s[105],vis[105];
    while(cin>>n)
    {
        memset(c,0,sizeof(c));
        memset(d,0,sizeof(d));
        memset(s,0,sizeof(s));
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++)
            cin>>a[i];
            cin>>m;
            for(int i=0;i<m;i++)
            cin>>b[i];
            for(int j=0;j<n;j++)
            for(int i=0;i<n;i++)
                if(a[j]==a[i])
                    {c[j]++;
                    //cout<<a[j]<<c[j]<<endl;
                    }
            for(int j=0;j<m;j++)
            for(int i=0;i<m;i++)
                if(b[j]==b[i])
                    {d[j]++;
                    //cout<<b[j]<<d[j]<<endl;
                    }
                   /* for(int i=0;i<n;i++)
                                cout<<"c"<<c[i]<<endl;
                                for(int i=0;i<m;i++)
                                cout<<"d"<<d[i]<<endl;*/

                    for(int i=0;i<n;i++)
                        for(int j=0;j<m;j++)
                        if(a[i]==b[j])
                        {
                            s[i]=c[i]-d[j];
                            vis[i]=1;
                        }
                        for(int i=0;i<n;i++)
                            if(vis[i]==0)
                        {
                            s[i]=c[i];
                        }

                        int maxn;
                        maxn=0;
                        for(int i=0;i<n;i++)
                           {
                               if(s[i]>maxn)
                            maxn=s[i];}
                            //for(int i=0;i<n;i++)
                             //   cout<<s[i]<<endl;
                        cout<<maxn<<endl;





    }
}


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

using namespace std;

typedef long long int ll;

int N;
ll activity[2005];
int indices[2005];

ll dp[2002][2002];

int comp(int a,int b){
    return activity[a]>activity[b];
}

int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        scanf("%lld",activity+i);
        indices[i]=i;
    }

    sort(indices+1,indices+N+1,comp);

    for(int i=1;i<=N;i++){
        int index=indices[i];
        for(int j=0;j<i;j++){
            int left=j,right=i-left-1;
            dp[left+1][right]=max(dp[left+1][right],activity[index]*(index-left-1)+dp[left][right]);
            dp[left][right+1]=max(dp[left][right+1],activity[index]*(N-right-index)+dp[left][right]);
        }
    }

    ll ans=0;
    for(int i=0;i<=N;i++) ans=max(ans,dp[i][N-i]);

    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 24344
#include <iostream>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,n){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"
#define PI 3.141592653589793

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

#define pii pair<int,int>

string b[100];
vector<pii> graph[100][100];
queue< pii > q;
int d[100][100];

int main(){
  int H,W; cin>>H>>W;
  REP(i,H){
    cin>> b[i];
  }
  int count = 0;
  REP(i,H){
    REP(j,W){
      if(b[i][j]=='.'){
        ++count;
        
        if(j+1<W && b[i][j+1]=='.'){
          graph[i][j].push_back(  make_pair(i,j+1) );
          graph[i][j+1].push_back( make_pair(i,j)  );
        }
        if(i+1<H && b[i+1][j]=='.'){ 
          graph[i][j].push_back( make_pair(i+1,j) );
          graph[i+1][j].push_back( make_pair(i,j) );
        }
      }
    }
  }
  
  FILL2(d,H,W,-1);
  d[0][0] = 1;
  q.push(make_pair(0,0));
  while(!q.empty()){
    int v = q.front().first;
    int w = q.front().second;
    q.pop();
    for(pii nxt:graph[v][w]){
      if( d[nxt.first][nxt.second] != -1 ){continue;}
      d[nxt.first][nxt.second] = d[v][w]+1;
      q.push( nxt );
    }
  }  
  if(d[H-1][W-1]==-1){
    cout << "-1\n";
  }else{
    cout << count - d[H-1][W-1] <<"\n";
  }
  
}

Measured memory_bytes: 640
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;

const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 1e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{   
   	ll n, d;
   	cin >> n >> d;
   	ll ans = 0;
   	while(n--)
   	{
   		ll x, y;
   		cin >> x >> y;
   		ll z = x*x + y * y;
   		ld zz = sqrt(z);
   		if(zz <= d)
   			ans++;
   	}
   	cout << ans << '\n';

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 3696
import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n,m = m()

if m == 1 or 2*n-1 == m:
    print("No")
else:
    print("Yes")
    if n == 2:
        ans = [1,2,3]
        print(jo(ans))
    else:
        if m == 2:
            a = [3,2,1,4]
            ans = [i + 5 for i in range(n-2)] + a + [i + n+3 for i in range(n-3)]
        else:
            a = [m-1,m,m+1,m-2]
            i = 0
            ans = []
            for j in range(2*n-4):
                i += 1
                if j == n-2:
                    ans += a
                    i -= 1
                else:
                    if i == m-2:
                        i += 4
                    ans.append(i)
        print(jo(ans))





Measured memory_bytes: 79080
n = input()
a = input().split(" ")
a = [int(b) for b in a]
a.sort()
while True:
    a = list(a)
    if len(a) <= 2:
        break
    c = a.pop(0)
    d = a.pop(0)
    synth = (c + d) / 2
    a.append(synth)
    a.sort()
print((a[0] + a[1]) / 2)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();  //トータル宿泊数
		int K = sc.nextInt();  //最初の宿泊数
		int X = sc.nextInt();  //割引前価格
		int Y = sc.nextInt();  //割引後価格
		
		System.out.println(N <= K ? N * X : (K * X) + ((N - K) * Y));
		

	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    vector<queue<char>> c(3);
    rep(i, 3){
        string s; cin >> s;
        rep(j, s.size()) c[i].push(s[j]);
    }

    ll next = 0;
    while(1){
        if(c[next].empty()) break;
        char p = c[next].front();
        c[next].pop();
        next = (p == 'a' ? 0 : (p == 'b' ? 1 : 2));
    }
    cout << (next == 0 ? "A" : (next == 1 ? "B" : "C")) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
  int n;
  string s;
  bool f=true;
  vector<string> w;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    w.push_back(s);
    if(i!=0){
      int x=w[i-1].length();
      if(s[0]!=w[i-1][x-1])f=false;
    }
  }
  sort(w.begin(),w.end());
  for(int i=0;i<n;i++){
    if(i!=0){
      if(w[i]==w[i-1])f=false;
    }
  }
  if(f)puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MOD (int)(1e9 + 7);

using namespace std;

const int N = 1100;

char s[N][N];
ll dp[N][N];

int main() {
    int h, w;
    cin >> h >> w;
    for(int i = 1 ; i <= h ; i++) {
        for(int j = 1 ; j <= w ; j++) {
            cin >> s[i][j];
        }
    }

    for(int i = 1 ; i <= h ; i++) {
        for(int j = 1 ; j <= w ; j++) {
            if(i == 1 and j == 1)
                dp[i][j] = 1;
            else if(s[i][j] == '#')
                dp[i][j] = 0;
            else 
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
        }
    }

    cout << dp[h][w] << '\n';
    return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

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

    vector<string> d = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    rep(0, 7) {
        if (d[i] == s) cout << (7 - i);
    }
    cout << endl;

    return 0;
}


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

int main(){

  int n;
  cin>>n;
  vector<string> data(n);
  for (int i=0;i<n;i++){
    cin>>data.at(i);
  }
  
  string answer="Yes";
  
  for (int i=1;i<n;i++){
    int size=int((data.at(i-1)).size());
    if (data.at(i-1).at(size-1)!=data.at(i).at(0)){
      answer="No";
      break;
    }
  }
  
  for (int i=0;i<n-1;i++){
    
    if (answer=="No"){
      break;
    }
    
    for (int j=i+1;j<n;j++){
      if (data.at(i)==data.at(j)){
        answer="No";
        break;
      }
    }

  }
  
  cout<<answer<<endl;
  
  
  
  
}
  













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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n=3;
    string s;
    REP(i,n){
        cin>>s;
        cout<<s[i];
    }
    cout<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 384
// Igorjan94, template version from 13 October 2017. C++17 version, modified 18 march 2020 (writeln<tuple>, whole->all) {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <iomanip>

using namespace std;

#define FOR(i, m, n) for (int i = m; i <  (int) (n); ++i)
#define ROF(i, m, n) for (int i = m; i >= (int) (n); --i)
#define forn(i, n)   for (int i = 0; i < (int) (n); ++i)
#define  fori1(n)    for (int i = 1; i < (int) (n); ++i)
#define  forj1(n)    for (int j = 1; j < (int) (n); ++j)
#define   fori(n)    for (int i = 0; i < (int) (n); ++i)
#define   forj(n)    for (int j = 0; j < (int) (n); ++j)
#define     SZ(a)    int(size(a))

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

#define pb push_back
#define all(a) begin(a), end(a)
#define ints(a...) int a; readln(a)

[[maybe_unused]] const int MOD = 1000000007;
[[maybe_unused]] const int INTMAX = numeric_limits<int>::max();

#define ttt12i template<class T1, class T2> inline
#define  ttti  template<class T> inline

void writeln(){cout<<"\n";}ttti void print(T&& a);ttti void priws(T&& a);ttti void read(T& a);
template<class... Args> inline void readln(Args&... args){(read(args),...);}
template<class H, class...T> inline void writeln(H&& h,T&&...t){priws(h);(print(t),...);writeln();}

//Igorjan
//}}}

void run()
{
    ints(n, m);
    vector<int> a(m);
    readln(a);
    int sum = accumulate(all(a), 0);
    if (sum > n)
        writeln(-1);
    else
        writeln(n - sum);
}

//{{{
int main()
{
    ios_base::sync_with_stdio(false);
    run();
    cerr << fixed << setprecision(0) << "Execution time = " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

#define a _a
#define n _n
ttt12i ostream&operator<<(ostream&os,pair<T1,T2>const&a);
template<typename T,typename D=decltype(*begin(declval<T>())),typename enable_if<!is_same<T,basic_string<char>>::value>::type* =nullptr>
ostream&operator<<(ostream&os,T const&a){auto it=begin(a);if(it!=end(a))os<<*it++;while(it!=end(a))os<<"\n "[is_fundamental<typename T::value_type>::value]<<*it++;return os;}
ttt12i ostream&operator<<(ostream&os,pair<T1,T2>const&a){return os<<a.first<<" "<<a.second;}
ttt12i istream&operator>>(istream&is,pair<T1,T2>&a){return is>>a.first>>a.second;}
ttti   istream&operator>>(istream&is,vector<T>&a){fori(a.size())is>>a[i];return is;}
ttti void print(T&&a){cout<<" "<<a;}
ttti void priws(T&&a){cout<<a;}
ttti void read(T&a){cin>>a;} //}}}


Measured memory_bytes: 3272
N = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

points = b_list[a_list[0] - 1]
for i in range(1, N):
    points += b_list[a_list[i] - 1]
    if a_list[i] == a_list[i - 1] + 1:
        points += c_list[a_list[i - 1] - 1]
print(points)

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

int N, M;
LL S[5050], ans;

struct SegTree{
    LL Max[20202];

    void update(int id, int s, int e, int t, LL v){
        if (e < t || t < s) return;
        if (s == e){
            Max[id] = v;
            return;
        }
        int mid = (s+e)/2;
        update(id*2, s, mid, t, v);
        update(id*2+1, mid+1, e, t, v);
        Max[id] = max(Max[id*2], Max[id*2+1]);
    }

    LL RMQ(int id, int s, int e, int ts, int te){
        if (e < ts || te < s) return 0;
        if (ts <= s && e <= te) return Max[id];
        int mid = (s+e)/2;
        return max(RMQ(id*2, s, mid, ts, te), RMQ(id*2+1, mid+1, e, ts, te));
    }
} T[220];

void DNC(int s, int e, int l, int r){
    if (s > e) return;
    int mid = (s+e)/2;
    LL Max=-(1ll<<60), p;
    for (int i=max(mid, l); i<=r; i++){
        LL sum=0;
        for (int j=1; j<=M; j++) sum += T[j].RMQ(1, 1, N, mid, i);
        sum -= S[i] - S[mid];
        if (Max < sum) Max = sum, p = i;
    }
    ans = max(ans, Max);
    DNC(s, mid-1, l, p);
    DNC(mid+1, e, p, r);
}

int main(){
    scanf("%d %d", &N, &M);
    for (int i=2; i<=N; i++) {
        scanf("%lld", &S[i]);
        S[i] += S[i-1];
    }
    for (int i=1; i<=N; i++) for (int j=1; j<=M; j++){
        LL x;
        scanf("%lld", &x);
        T[j].update(1, 1, N, i, x);
    }
    DNC(1, N, 1, N);
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

int main(){
	int W, H;
	vector<unsigned long long int> P, Q;

	cin>>W>>H;
	P.resize(W+1);
	Q.resize(H+1);

	unsigned long long int ans=0;

	int p, q;

	for(int i=0; i<W; i++){
		cin>>p;
		P[i]=p;
	}
	P[W]=100000000+1;
	sort(P.begin(), P.end());

	for(int i=0; i<H; i++){
		cin>>q;
		Q[i]=q;
	}
	Q[H]=100000000+1;
	sort(Q.begin(), Q.end());

	int p_index=0, q_index=0;
	for(int i=0; i<W+H; i++){
		if(P[p_index] <= Q[q_index]){
			ans+=P[p_index]*(H+1-q_index);
			p_index++;
		}else{
			ans+=Q[q_index]*(W+1-p_index);
			q_index++;
		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
  int N, C, K; cin >> N >> C >> K;
  vector<int> T(N);
  REP(i, N) cin >> T[i];
  sort(ALL(T));

  int ans = 0;
  ll bus;
  int people = C;
  int i = 0;

  while(i<N){
    if(people == C){
      people = 0;
      bus = T[i] + K;
      ans++;
    }

    if(T[i] <= bus && bus <= T[i] + K){
      people++;
      i++;
    }else{
      people = C;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[] ans=new boolean[n];
		Unionfind uf=new Unionfind(n);
		for(int i = 0; i<m; i++){
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			int z = sc.nextInt();
			uf.unite(x,y);
		}
		long count=0;
		for(int i=0; i<n; i++){
			if(!ans[uf.root(i)]){
				ans[uf.root(i)]=true;
				count++;
			}
		}
		System.out.println(count);
	}
	static class Unionfind{
		int[] parent;
		public Unionfind(int n){
			this.parent=new int[n];
			for(int i = 0; i<n; i++){
				parent[i]=i;
			}
		}
		public int root(int t){
			if(parent[t]==t){
				return t;
			}else{
				return parent[t]=root(parent[t]);
			}
		}
		public void unite(int x,int y){
			if(same(x,y)){
				return;
			}
			int xroot = root(x);
			int yroot = root(y);
			parent[yroot]=xroot;
		}
		public boolean same(int x,int y){
			return root(x)==root(y);
		}
	}
}


Measured memory_bytes: 92620
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

A, B = MI()
ans = A - B * 2

print(ans if ans > 0 else 0)


Measured memory_bytes: 43376
import java.util.*;

class Main {

	static int mat[][] = new int[105][105];

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		for(;;){
			int w = in.nextInt(), h = in.nextInt();
			if(w==0 && h==0) return ;
			int sx = in.nextInt(), sy = in.nextInt();
			int gx = in.nextInt(), gy = in.nextInt();
			int n = in.nextInt();
			for(int i=0; i<105; i++)
				for(int j=0; j<105; j++)
					mat[i][j] = -1;
			for(int i=0; i<n; i++){
				int c = in.nextInt(), d = in.nextInt(), x = in.nextInt(), y = in.nextInt();
				if(d==1){
					for(int j=0; j<2; j++)
						for(int k=0; k<4; k++)
							mat[x+j][y+k] = c;
				}
				else{
					for(int j=0; j<4; j++)
						for(int k=0; k<2; k++)
							mat[x+j][y+k] = c;
				}
			}
			
			if(mat[sx][sy]==-1){
				System.out.println("NG");
				continue;
			}
			dfs(sx,sy,mat[sx][sy]);
			System.out.println((mat[gx][gy]==-2)?"OK":"NG");
		}
	}
	
	static void dfs(int i, int j, int col){
		if(mat[i][j] != col) return ;
		mat[i][j] = -2;
		dfs(i+1,j,col);
		dfs(i,j+1,col);
		dfs(i-1,j,col);
		dfs(i,j-1,col);
		return ;
	}
	
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int a, b;
    int n, c = 0;
    cin >> n;
    bool ans = false;
    for(int i=0;i<n;++i) {
        cin >> a >> b;
        if(a == b) {
            ++c;
            if(c == 3) {
                ans = true;
            }
        } else {
            c = 0;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3640