akhauriyash/Code-Regression huggingface dataset:
#include <stdlib.h>
#include <string.h>
 
#define N 20001
char pStr[N];
 
typedef struct Roll{
  int indx;
  int diff;
} Roll;
 
int S1[N];
Roll S2[N];
 
int s1_top = 0;
 
int s1_pop()
{
  return S1[--s1_top];
}
 
void s1_push(int x)
{
  S1[s1_top++] = x;
}
 
int s2_top = 0;
 
Roll s2_Top()
{
  return S2[s2_top-1];
}
 
Roll s2_pop()
{
  return S2[--s2_top];
}
 
void s2_push(int indx, int diff)
{
  Roll x;
  x.indx = indx;
  x.diff = diff;
 
  S2[s2_top++] = x;
}

int main()
{
  int j, i,sum,a,c;
  
  scanf("%s", pStr);
 
  sum = 0;
  i = 0;
  while ( (c = pStr[i]) != 0 ) {
    if ( c == '\\' ) {
      s1_push(i);
    } else if ( s1_top > 0 && c == '/') {
      j = s1_pop();
      a = i - j;
      sum += a;
      while ( s2_top > 0 && s2_Top().indx > j) {
	a += s2_pop().diff;
      }
      s2_push(j, a);
    }
    i++;
  }
 
  printf("%d\n", sum);
  printf("%d", s2_top);
  for ( i = 0 ; i < s2_top; i++ ) {
    printf(" ");
    printf("%d", S2[i].diff);   
  }
  printf("\n");   
 
  return 0;
}

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

int main(){
	int n; cin>>n;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	int cnt=1;
	rep(i,n){
		if(cnt==v[i]) cnt++;
	}
	cnt--;
	if(n-cnt==n) cout<<-1<<endl;
	else cout<<n-cnt<<endl;
}

Measured memory_bytes: 3988
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>
//O(n^2)
void stupid(){
    int N;
    int cnt;
    std::cin>>N;
    std::vector<unsigned int>A(N);
    for(int i=0;i<N;++i){
        std::cin>>A[i];
    }
    cnt=0;
    for(int i=0;i<N;++i){
        bool flag=1;
        for(int j=0;j<N;++j){
            if(i!=j && A[i]%A[j]==0){
                flag=0;
                break;
            }
        }
        if(flag==1){
            cnt++;
        }
    }
    std::cout<<cnt;
}

//O(n^2)
void stupid1(){
    int N;
    int cnt;
    std::cin>>N;
    std::vector<unsigned int>A(N);
    for(int i=0;i<N;++i){
        std::cin>>A[i];
    }
    std::sort(A.begin(),A.end());
    cnt=0;
    for(int i=0;i<N;++i){
        bool flag=1;
        for(int j=0;A[j]<=A[i];++j){
            if(i!=j && A[i]%A[j]==0){
                flag=0;
                break;
            }
        }
        if(flag==1){
            cnt++;
        }
    }
    std::cout<<cnt;
}

void correct(){
    int N;
    // int cnt;
    std::cin>>N;
    std::vector<unsigned int>A(N);
    // std::vector<bool>flags(N,1);
    int startVal;
    for(int i=0;i<N;++i){
        std::cin>>A[i];
    }
    std::sort(A.begin(),A.end());
    std::unordered_map<int,int> maps;
    // for(int i=*(A.begin());i<=A.back();++i){
    for(auto itr=A.begin();itr!=A.end();++itr){
        maps[*itr]++;
    }
    int cnt=0;
    for(int i=0;i<N;++i){
        if(maps[A[i]]==1)
            cnt++;

        for(int j=A[i];j<=A.back();j=j+A[i]){
            maps[j]=0;
        }
    }
    std::cout<<cnt;
}

int main(){
    // stupid();
    // stupid1();
    correct();
    return 0;
}

Measured memory_bytes: 43340
#include<stdio.h>

int main(void){
	int m;
	int min, max;
	int gap = 0;
	int pos;
	int i;
	int score[2000] = {0};
	
	while(1){
	gap = 0;
	scanf("%d %d %d", &m, &min, &max);
	if ( m == 0 && min == 0 && max == 0 ) {
		break;
	}
	for ( i = 0; i < m; i++ ) {
		scanf("%d", &score[i]);
	}
	
	for ( i = min; i <= max; i++ ) {
		if ( gap <= score[i-1] - score[i] ) {
			gap = score[i-1] - score[i];
			pos = i;
		}
	}
	printf("%d\n", pos);
	}
	return 0;
}


Measured memory_bytes: 2052
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	void run() {
		Scanner sc = new Scanner(System.in);
		int count = 0;
		int n = sc.nextInt();
		int[] S = new int[n];
		
		for(int i = 0; i < n; i++) {
			S[i] = sc.nextInt();
		}
		Arrays.sort(S);
		int q = sc.nextInt();
		int[] T = new int[q];
		for(int j = 0; j < q; j++) {
			T[j] = sc.nextInt();
		}
		for(int i = 0; i < q; i++) {
			int left = 0;
			int right = n;
			while(left < right) {
				int mid = (left + right)/2;
				if(T[i] == S[mid]) {
					count++;
					break;
				}
				else if(T[i] < S[mid]) right = mid;
				else left = mid + 1;
			}
		}
		System.out.println(count);
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

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


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

if min(a) ==0:
    ans =0
else:
    order =0
    for i in a:
        order = order+len(str(i))-1

    if order >18:
        ans = -1
    else:
        ans =1
        for i in a:
                ans = ans*i
        if ans >10**18:
            ans=-1
print (ans)

Measured memory_bytes: 21672
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define pb push_back
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(type,arr,n)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//=======================
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
//=======================
const int MOD = 1000000007;
const int N = 300005, M = N;
//=======================
vi g[N],adj[N];
int n, m, s, w, W, S, k, i, l, j, p, q, pr, fi, md;


void abhinay()
{
   
    #ifndef ONLINE_JUDGE   
        freopen("input.txt", "r", stdin);   
        freopen("output.txt", "w", stdout);   
    #endif   
    
}

int main(){
    abhinay();
    cin>>n>>k;
    vi dp(n+1,MOD),v(n+1); 
    dp[0]=0;
    fo(i,n) cin>>v[i];
    dp[1] = abs(v[1] - v[0]); 
    for (int i = 2; i < n; i++)
        for (int j =1;j<=k;j++)
            if(i-j>=0)
            {
        dp[i] = min(abs(v[i] - v[i-j]) + dp[i-j],dp[i]);
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 18040
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

class SegmentTree {
   public:
    using value_type = int64_t;

    SegmentTree(int64_t n)
            : n(n), cap(pow(2, ceil(log2(n)))), values(2 * cap - 1, 0), delay(2 * cap - 1, -1L) {}
  
    void update(int64_t a, int64_t b, int64_t v, int64_t idx = 0, int64_t l = 0,
                     int64_t r = -1) {
        if (r < 0) {
            r = cap;
        }

        if (a >= r || b <= l) {
            return;
        }

        if (a <= l && r <= b) {
            values[idx] = v * (r - l);
            delay[idx] = v;
            return;
        }

        auto left_idx = 2 * (idx + 1) - 1;
        auto right_idx = 2 * (idx + 1);

        if (delay[idx] >= 0) {
            update(l, (l + r) / 2, delay[idx], left_idx, l, (l + r) / 2);
            update((l + r) / 2, r, delay[idx], right_idx, (l + r) / 2, r);
            delay[idx] = -1;
        }

        update(a, b, v, left_idx, l, (l + r) / 2);
        update(a, b, v, right_idx, (l + r) / 2, r);
      
        values[idx] = values[left_idx] + values[right_idx];
    }
  
    value_type get(int64_t pos) {
        return query(pos, pos + 1);
    }

    value_type query(int64_t a, int64_t b, int64_t idx = 0, int64_t l = 0,
                     int64_t r = -1) {
        if (r < 0) {
            r = cap;
        }

        if (a >= r || b <= l) {
            return 0;
        }

        if (a <= l && r <= b) {
            return values[idx];
        }

        auto left_idx = 2 * (idx + 1) - 1;
        auto right_idx = 2 * (idx + 1);
      
        if (delay[idx] >= 0) {
            update(l, (l + r) / 2, delay[idx], left_idx, l, (l + r) / 2);
            update((l + r) / 2, r, delay[idx], right_idx, (l + r) / 2, r);
            delay[idx] = -1;
        }

        auto left_v = query(a, b, left_idx, l, (l + r) / 2);
        auto right_v = query(a, b, right_idx, (l + r) / 2, r);

        return left_v + right_v;
    }

   private:
    int64_t n;
    int64_t cap;
    vector<value_type> values;
    vector<value_type> delay;
};

main() {
    int64_t n, q;
    cin >> n >> q;

    SegmentTree tree(n);
  
    for (auto i : irange(0L, q)) {
        int64_t a, b;
        cin >> a >> b;
      
        auto r = irange(0L, a);
        auto c = *partition_point(r.begin(), r.end(), [&](int64_t pos) {
            auto v = tree.get(pos);
            auto v2 = tree.query(pos + 1, a);
            return v2 + b < v * (a - pos - 1);
        });
        auto v = tree.get(c);
        auto v2 = tree.query(c + 1, a);

        b -= v * (a - c - 1) - v2;
        auto l = a - c;
        tree.update(c, c + b % l, v + b / l + 1);
        tree.update(c + b % l, a, v + b / l);
    }
  
    for (auto i : irange(0L, n)) {
        cout << tree.get(i) << "\n";
    }
}


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

public class Solution
{
    public static void Main()
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();
        var n = s.Length;

        var first = Enumerable.Repeat(-1, 'z' - 'a' + 1).ToArray();
        var next = Enumerable.Range(0, 'z' - 'a' + 1).Select(_ => Enumerable.Repeat(-1, s.Length).ToArray()).ToArray();
        for (int i = 0; i < s.Length; i++)
        {
            var a = s[i] - 'a';
            if (first[a] == -1)
            {
                first[a] = i;
            }
            for (int j = i; j >= 0 && next[a][j] == -1; j--)
            {
                next[a][j] = i;
            }
        }
        for (int a = 0; a < next.Length; a++)
        {
            for (int j = next[a].Length - 1; j >= 0 && next[a][j] == -1; j--)
            {
                next[a][j] = first[a];
            }
        }

        long len = 0;
        var index = 0;
        foreach (var c in t)
        {
            var a = c - 'a';
            var nextIndex = next[a][index];
            if (nextIndex == -1)
            {
                Console.WriteLine(-1);
                return;
            }
            if (nextIndex < index)
            {
                len += n - (index - nextIndex);
            }
            else
            {
                len += nextIndex - index;
            }

            len++;
            index = (nextIndex + 1) % n;
        }

        Console.WriteLine(len);
    }
}

Measured memory_bytes: 35608
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
typedef long long LL;
const int maxN = 1e5 + 7;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

int n, S;
int X[maxN];
LL P[maxN];

int main() {

	n = ri(), S = ri();
	rep (i, 1, n) X[i] = ri(), P[i] = ri();
	LL res = 0;
	for (int l = 1, r = n; l <= r; ) {
		if (S <= X[l]) {
			res += X[r] - S;
			break;
		}
		if (S >= X[r]) {
			res += S - X[l];
			break;
		}
		res += X[r] - X[l];
		if (P[l] >= P[r])
			while (X[l] < S && S < X[r] && P[l] >= P[r]) P[l] += P[r--];
		else 
			while (X[l] < S && S < X[r] && P[l] < P[r]) P[r] += P[l++];
	}
	printf("%lld\n", res);
	
	return 0;
}


Measured memory_bytes: 1408
tramp = [[i for i in range(1,14)],
        [i for i in range(1,14)],
        [i for i in range(1,14)],
        [i for i in range(1,14)]]
mark = {"S": 0,"H": 1, "C": 2, "D":3}
itomark = {0: "S", 1:"H",2:"C", 3:"D"}
n = int(input())
for i in range(n):
    m, num = input().split()
    num = int(num)-1
    tramp[mark[m]][num] = 0
for i in range(4):
    for j in range(13):
        if tramp[i][j] != 0:
            print(itomark[i],tramp[i][j])


Measured memory_bytes: 5616
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	m := make(map[int]bool)
	for i := 2; i*i <= a; i++ {
		for a%i == 0 {
			a /= i
			m[i] = true
		}
	}
	if a > 1 {
		m[a] = true
	}

	ans := 1
	for k := range m {
		if b%k == 0 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    R = [0] * n
    for i in range(n):
        R[i] = int(input())

    min_R_front = [0] * n
    min_R_front[0] = R[0]
    for i in range(1, n):
        if R[i] < min_R_front[i - 1]:
            min_R_front[i] = R[i]
        else:
            min_R_front[i] = min_R_front[i - 1]

    max_R_back = [0] * n
    max_R_back[-1] = R[-1]
    for i in reversed(range(n - 1)):
        if R[i] > max_R_back[i + 1]:
            max_R_back[i] = R[i]
        else:
            max_R_back[i] = max_R_back[i + 1]

    ans = -float("inf")
    for i in range(n - 1):
        if ans < max_R_back[i + 1] - min_R_front[i]:
            ans = max_R_back[i + 1] - min_R_front[i]
    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 16552
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  int n = s.size();
  int ans = 1e9;
  rep(i, 0, 26) {
    int c = 0, maxv = 0;
    rep(j, 0, n) {
      if (s[j] == (char)(i + 'a')) {
        chmax(maxv, c);
        c = 0;
      } else {
        c++;
      }
    }
    chmax(maxv, c);
    chmin(ans, maxv);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
l=[int(input()) for i in range(n)]

lis=[i for i in l if i%10!=0]

sum_l=sum(l)

if sum_l%10!=0:
  print(sum_l)
else:
  if len(lis)==0:
    print(0)
  else:
    print(sum_l-min(lis))

Measured memory_bytes: 9052
#include<stdio.h>
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int i;
	long long int a[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int p = 1000000007;
	long long int ans = 0;
	for (i = 0; i < n; i++)
		ans += a[i];
	ans %= p;
	ans = ans * ans % p;
	for (i = 0; i < n; i++)
		ans = (ans - a[i] * a[i] % p + p) % p;
	if (ans % 2 > 0)
		ans += p;
	ans /= 2;
	printf("%lld\n", ans % p);
	return 0;
}

Measured memory_bytes: 3292
while True:
    n,m,a=map(int,raw_input().split())
    if n==m==a==0:break
    L=range(n+1)
    data=[map(int,raw_input().split()) for i in range(m)]
    data.sort()
    for i,j,k in data:
        L[j],L[k]=L[k],L[j]
    print L[a]

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1002
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int mat[MAXN][MAXN];
int sum[MAXN][MAXN];
int cntIt(int l, int r, int u, int d, int k) {
    int c = sum[d][r];
    if (u - 1 >= 0) c -= sum[u - 1][r];
    if (l - 1 >= 0) c -= sum[d][l - 1];
    if (l - 1 >= 0 && u - 1 >= 0) c += sum[u - 1][l - 1];
    if (c > k && (l == r)) return -1;
    if (c > k) return inf;
    return c;
}
int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    char c;
    int res = inf;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> c;
            mat[i][j] = c - '0';
            sum[i][j] = c - '0';
            if (i - 1 >= 0) sum[i][j] += sum[i - 1][j];
            if (j - 1 >= 0) sum[i][j] += sum[i][j - 1];
            if (i - 1 >= 0 && j - 1 >= 0) sum[i][j] -= sum[i - 1][j - 1];
        }
    }
    for (int i = 0; i < (1 << h) - 1; i++) {
        vector<int> indexs;
        indexs.pb(0);
        for (int j = 1; j < h; j++) {
            if ((i & (1 << j)) != 0) {
                indexs.pb(j);
            }
        }
        indexs.pb(h);
        int cur = 0;
        int lastIndex = 0;
        bool notFound = false;
        for (int j = 0; j < w; j++) {
            int mx = 0;
            for (int kk = 0; kk < sz(indexs) - 1; kk++) {
                int c = cntIt(lastIndex, j, indexs[kk], indexs[kk + 1] - 1, k);
                if (c == -1) {
                    mx = -1;
                    notFound = true;
                    break;
                }
                mx = max(mx, c);
            }
            if (notFound) {
                break;
            }
            if (mx == inf) {
                cur++;
                lastIndex = j;
            }
        }
        if (!notFound)
            res = min(res, cur + sz(indexs) - 2);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 2304
#include<stdio.h>
#define MAX 10000
#define NIL -1
struct node{int p,l,r};
struct node T[MAX];
int n;
void preParse(int);
void inParse(int);
void postParse(int);
void print(int);

int main(){
    int i,v,l,r,root;
    scanf("%d",&n);
    for(i=0;i<n;i++) T[i].p=NIL;//初期化
    for(i=0;i<n;i++){
        scanf("%d %d %d",&v,&l,&r);
        T[v].l=l;
        T[v].r=r;
        if(l!=NIL) T[l].p=v;
        if(r!=NIL) T[r].p=v;
    }
    for(i=0;i<n;i++){
        if(T[i].p==NIL) root=i;
    }
    print(root);
    return 0;
}
void preParse(int id){
    if(id == NIL) return;
    printf(" %d",id);
    preParse(T[id].l);
    preParse(T[id].r);
}
void inParse(int id){
    if(id == NIL) return;
    inParse(T[id].l);
    printf(" %d",id);
    inParse(T[id].r);
}
void postParse(int id){
    if(id == NIL) return;
    postParse(T[id].l);
    postParse(T[id].r);
    printf(" %d",id);
}
void print(int id){
    printf("Preorder\n");
    preParse(id);
    printf("\n");
    printf("Inorder\n");
    inParse(id);
    printf("\n");
    printf("Postorder\n");
    postParse(id);
    printf("\n");
}



Measured memory_bytes: 2100
import sys
readline = sys.stdin.readline

# 現在のインデックスを持ちながらBFSしてみよう

N = int(readline())
S = readline().rstrip()

from collections import deque
q = deque([])

for i in range(10):
  q.append(["",0,str(i)])
  
ans = 0
while q:
  # 現在の文字列、探し始めるインデックス、探している文字列
  num, ind, target = q.popleft()
  while ind < len(S):
    if S[ind] == target:
      break
    ind += 1
  else:
    continue
  num += target
  if len(num) == 3:
    ans += 1
    continue
  for i in range(10):
    q.append([num, ind + 1, str(i)])

print(ans)

Measured memory_bytes: 9676
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <deque>
#include <math.h>
#include <cstring>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <stack>
#include<cassert>
#include <cfloat>
#include <list>
using namespace std ;
#define ll long long
#define submitStage int TCF = 1 ;
#define testStage int TCF = 1000 ;
#define testMyStupedCode TCF--
void FastInputOutput(){
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
void ReadFromFile( string name , string extention ){
    string fullPath = name + "." + extention ;
    freopen( fullPath.c_str() , "r" , stdin ) ;
}
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}
inline char C(){
    char c ;
    scanf( "%c" , &c ) ;
    return c ;
}
inline ll power(ll x, ll p, ll m){
    ll res = 1;
    while(p){
        if(p & 1)
            res = (res * x) % m;
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}
long double ModLog(long double base, long double x) {
    return (logl(x) / logl(base));
}

const int N = 1e6;
int n, k;
int dp[N];
int a[N];
int solve(int idx){
     if(idx == n - 1)
          return 0;
     int &ret = dp[idx];
     if(~ret)
          return ret;
     ret = 1e9 + 5;
     for(int i  = 1; i <= k; ++i)
          if(idx + i < n)
               ret = min(ret, abs(a[idx] - a[idx + i]) + solve(idx + i));
     return ret;
}
int main(){
     memset(dp, -1, sizeof(dp));
     n = D(), k = D();
     for(int i = 0; i < n; ++i)
          a[i] = D();
     printf("%d", solve(0));
}


Measured memory_bytes: 11136
use std::fmt::Write;
use std::io::*;

fn main() {
  let input = {
    let mut buf = vec![];
    stdin().read_to_end(&mut buf);
    unsafe { String::from_utf8_unchecked(buf) }
  };
  let mut lines = input.split('\n');

  let n = lines.next().unwrap().parse().unwrap();
  let m = lines.next().unwrap().parse().unwrap();

  let targets = lines.next().unwrap()
    .split(' ').map(|s| s.parse::<usize>().unwrap());
  let iter = lines.take(m).map(|l|
    l.split(' ').map(|s| s.parse().unwrap())
  );

  let mut pts = vec![0; n];

  for (a, ints) in targets.zip(iter) {
    let mut bonus = 0;

    for (b, pt) in ints.zip(&mut pts) {
      if a == b { *pt += 1; }
      else { bonus += 1; }
    }
    pts[a - 1] += bonus;
  }

  let mut result = String::with_capacity(n * 2);
  for pt in pts { writeln!(result, "{}", pt); }
  print!("{}", result);
}



Measured memory_bytes: 5028
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];
    let t = v[2];

    let ans = (t / a) * b;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){
	int x,y;
	
	while (1){
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		if (x > y){
			cout << y << " " << x << endl;
		}
		else{
			cout << x << " " << y << endl;
		}
	}
	




	return 0;
}


Measured memory_bytes: 3068
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    cin >> N;
    vi data(N);
    for (int i = 0; i < N; i++) {
        cin >> data[i];
    }
    sort(data.begin(), data.end());
    ll ans = 0;
    for (int i = 2; i < N; i++) {
        for (int j = 0; j < i - 1; j++) {
            for (int k = j + 1; k < i; k++) {
                if (data[j] + data[k] > data[i]) {
                    ans += ll(i - k);
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 1000000
#define MOD 1000000001
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pi 3.14159265358979323846
#define Q ll _; cin >> _; while(_--)
#define endl "\n"
#define cy cout << "YES\n";
#define cn cout << "NO\n";
#define flush fflush(stdout);

int main(){

    ll a[6];
    ll k;
    for(ll i=1;i<6;i++){
        cin >> a[i];
        if(!a[i]){
            k = i;
        }
    }
    cout << k << endl;

}

//    cout << fixed << setprecision(12);


Measured memory_bytes: 3616
<?php


[$N] = fscanf(STDIN, "%d");
$A = fscanf(STDIN, str_repeat("%d", $N));
$start = $A[0];
$mon = 1000;
$max = 0;
for($i=1;$i<$N;$i++){
//    if($start != 0){
    if($A[$i] > $start){
        if($max != 0){
            if($A[$i] > $max){
                $max = $A[$i];
            }else{
                $kabu = intdiv($mon, $start);
                $mon -= $kabu * $start;
                $mon += $kabu * $max;
                $start = $A[$i];
                $max = 0;
            }
        }else{
            $max = $A[$i];
        }
    }else{
        if($max != 0){
            $kabu = intdiv($mon, $start);
            $mon -= $kabu * $start;
            $mon += $kabu * $max;
            $start = $A[$i];
            $max = 0;
        }else{
            $start = $A[$i];
        }

    }


}
if($max != 0){
    $kabu = intdiv($mon, $start);
    $mon -= $kabu * $start;
    $mon += $kabu * $max;
    $max = 0;
}
echo $mon;

Measured memory_bytes: 16192
import math

a,b = map(int, input().split())
t = math.gcd(a,b)

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

cnt = len(set(prime_decomposition(t)))

print(cnt+1)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll s,w;cin>>s>>w;
    if (s<=w) {
        cout << "un";
    }
    cout << "safe" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
const int N=15;
int a[N],b[N][N],n,m,x;
int main(){
	cin>>n>>m>>x;
	int ans=1e9;
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(int j=0;j<m;j++) cin>>b[i][j];
	}
	for(int i=0;i<(1<<n);i++){
		int f=0;
		int d[m]={};
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				f+=a[j];
				for(int k=0;k<m;k++){
					d[k]+=b[j][k];
				}
			}
		}
		int s=1;
		for(int j=0;j<m;j++) if(d[j]<x) s=0;
		if(s) ans=min(f,ans);
	}
	cout<<(ans==1e9?-1:ans);
	return 0;
}


Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;
long long n,ans;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;

    for (int i = 0; i < 3; i++) {
        if (s1[i] == s2[i]) {
            ans++;
        }
    }

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


Measured memory_bytes: 256
macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };

    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

fn main() {
    let _ = scan!(usize);
    let mut vs = scan!(i64;;);
    for i in 0..vs.len() - 1 {
        vs[i + 1] += vs[i]
    }

    let mut min: Vec<i64> = vec![];
    for i in 0..vs.len() - 1 {
        min.push((vs[i] - vs.last().unwrap() + vs[i]).abs())
    }

    println!("{}", min.iter().min().unwrap())
}


Measured memory_bytes: 10492
# include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s;
	int ans = 0;
	cin >> s;
	if(s == "SUN")ans = 7;
	if(s == "MON")ans = 6;
	if(s == "TUE")ans = 5;
	if(s == "WED")ans = 4;
	if(s == "THU")ans = 3;
	if(s == "FRI")ans = 2;
	if(s == "SAT")ans = 1;
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll a,b;
    cin>>a>>b;
    ll M = max(a,b);
    ll m = min(a,b);
    if(M-m>=2){
        cout<<"Alice"<<endl;
    }else{
        cout<<"Brown"<<endl;
    }
    return  0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j,t,m[10000];
  long  s;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d",&m[i]);
    }
    for(i=0;i<n;i++){
      for(j=1;j+i<n;j++){
	if(m[j-1]>m[j]){
	  t=m[j-1];
	  m[j-1]=m[j];
	  m[j]=t;
	}
      }
    }
    s=0;
    for(i=0;i<n;i++){
      s+=m[i]*(n-i-1);
    }
    printf("%ld\n",s);
  }
  return 0;
}

Measured memory_bytes: 636
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

int c[10][10];

int main() {
    int H, W;
    cin >> H >> W;
    rep(i, 10) {
        rep(j, 10) {
            cin >> c[i][j];
        }
    }
    rep(k, 10) {
        rep(i, 10) {
            rep(j, 10) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
#if 0
    rep(i, 10) {
        rep(j, 10) {
            printf("%4d ", c[i][j]);
        }
        printf("\n");
    }
#endif
    int tmp;
    uint64_t ret = 0;
    rep(i, H) {
        rep(j, W) {
            cin >> tmp;
            if(tmp == -1 || tmp == 1 )
                continue;
            ret += c[tmp][1];
        }
    }
    cout << ret << endl;

    return 0;
}



Measured memory_bytes: 3184
module Main where

import Data.List as List
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as BS
import Control.Monad as M
import Data.Maybe as Maybe

main :: IO ()
main =
    print =<< (\a -> a - 1) . (`div` 2) . (+ 1) <$> getInt

getInt :: IO Int
getInt = read <$> BS.unpack <$> BS.getLine

{-
splitLine :: IO [BS.ByteString]
splitLine = BS.words <$> BS.getLine

getInts :: IO (V.Vector Int)
getInts = V.fromList <$> List.map fst <$> Maybe.mapMaybe BS.readInt <$> splitLine
-}
getInts :: IO (V.Vector Int)
getInts = V.fromList <$> List.map fst <$> Maybe.mapMaybe BS.readInt <$> replicateM 3 BS.getLine

solve :: V.Vector Int -> IO ()
solve v = print $ (\a -> div (a - 1 + v V.! 2) a) $ max (v V.! 0) (v V.! 1)


Measured memory_bytes: 508
import java.util.*;
import java.io.*;

public class Main {
    static long mod = (long) 1e9 + 7;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        Long [] c = new Long[n + 1];
        for (int i = 1; i <= n; i++) c[i] = sc.nextLong();
        Arrays.sort(c, 1, n + 1, Comparator.reverseOrder());
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            long outerPow = pow(2, n - i);
            long firstInner = pow(2, i - 1);
            long secondInner = ((i - 1) * pow(2, i - 2)) % mod;
            long sum = (firstInner + secondInner) % mod;
            long total = (((outerPow * c[i]) % mod) * sum) % mod;
            ans = (ans + total) % mod;
        }
        ans = (ans * pow(2, n)) % mod;
        out.println(ans);
        out.close();
    }


    static long pow(long b, long e) {
        long ans = 1;
        while (e > 0) {
            if (e % 2 == 1)
                ans = ans * b % mod;
            e >>= 1;
            b = b * b % mod;
        }
        return ans;
    }

    static long inv(int x) {
        return pow(x, mod - 2);
    }



    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 58992
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;

int n, a[100010], p, q;
vector<pair<int,int>> op;

int main(){
	cin >> n;
	p = 0;
	for (int i = 0; i < n; ++i){
		cin >> a[i];
		if (a[i] >= 0) p++;
	}
	q = n - p;
	if (p == 0){p++; q--;}
	if (q == 0){p--; q++;}
	sort(a, a+n);
	for (int i = q; i < n-1; ++i){
		op.emplace_back(a[0], a[i]);
		a[0] -= a[i];
	}
	for (int i = 0; i < q; ++i){
		op.emplace_back(a[n-1], a[i]);
		a[n-1] -= a[i];
	}
	printf("%d\n", a[n-1]);
	for (auto &o: op) printf("%d %d\n", o.first, o.second);
}

Measured memory_bytes: 3188
#include <stdio.h>
int main(int argc, char const *argv[])
{
	int a ,b ,W;
	scanf("%d %d %d",&W,&a,&b);
	if(a+W >= b && a <= b ){
		printf("0\n");
	}
	else if(a+W >= b+W && a <= b+W ){
		printf("0\n");
	}
	else{
		if(b > a+W){
			printf("%d\n",b - (a+W) );
		}
		else if(b+W < a){
			printf("%d\n",a - (b+W) );
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n, d;
    cin >> n >> d;
    int x[n][d];
    rep(i, n) {
        rep(j, d) {
            cin >> x[i][j];
        }
    }

    int ans = 0;
    rep(i, n-1) {
        for(int j = i+1; j < n; j++) {
            
            int D = 0;
            rep(k, d) {
                D += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
            }

            for(int p = 1; p*p <= D; p++) {
                    if(p*p == D) {
                        ans++;
                    }
            }
        }
    }

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
let () =
  let a = Scanf.scanf "%s\n" (fun a -> a) in
  let input_chars = BatString.to_list a in
  let b = List.length (List.find_all (fun x -> x = 'o') input_chars) in
  print_int (b * 100 + 700);
  print_endline ""



Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, i;
  string S, T;
  cin >> N >> S >> T;
  REP(0, N, i) {
    cout << S[i] << T[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
s = []
c = []
for _ in range(M):
    _s, _c = list(map(int, input().split()))
    s.append(_s)
    c.append(_c)

if N == 1:
    ans = [0]
else:
    ans = [1]
    ans = ans + [0 for _ in range(N - 1)]

flag = True
dup = [-1 for _ in range(N)]
for i in range(M):
    idx = s[i] - 1
    if N > 1 and s[i] == 1 and c[i] == 0:
        flag = False
        break
    if dup[idx] != -1 and ans[idx] != c[i]:
        flag = False
        break
    ans[idx] = c[i]
    dup[idx] = 1

if flag == False:
    print(-1)
else:
    print(''.join(map(str, ans)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007;
vector<vector<double>>dp; // dp(i,j) probablity of coming j heads when i coins
vector<double>p;

double probhead(int n,int heads){

        if(dp[n][heads]!=-1){
            return dp[n][heads];
        }
        return dp[n][heads] = probhead(n-1,heads)*(1-p[n]) + probhead(n-1,heads-1)*p[n];

}
void solve(){
    int n;cin>>n;
    dp.resize(n+1,vector<double>(n+1,-1));
    p.resize(n+1);
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
    for(int i=0;i<=n;i++){
        dp[0][i]=0;
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        dp[i][0] = dp[i-1][0]*(1-p[i]);
    }

    double pr =0;
    for(int i=(n+1)/2;i<=n;i++){
          pr += probhead(n,i);
    }
    cout<<pr<<"\n";

}

int main(){
    //cin.tie(0);
    //cout.tie(0);
    //cin.sync_with_stdio(0);
    //cout.sync_with_stdio(0);

    cout.precision(10);
    int t=1;//cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	int sum=0;
	int a[n+1],b[n+1],c[n];
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) {
		cin>>b[i];
		sum+=b[i];
	}
	for(int i=1;i<=n-1;i++)
	cin>>c[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i+1]-a[i]==1)
		sum+=c[a[i]];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v, w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int n, d, x; cin >> n >> d >> x;
	vector<vector<int> > p(d, vector<int>(n));
	for (int i = 0; i < d; i++)
		for (int j = 0; j < n; j++)
			cin >> p[i][j];
	for (int i = 0; i + 1 < d; i++) {
		vector<int> dp(x + 1);
		for (int j = 0; j < n; j++)
			for (int k = 0; k + p[i][j] <= x; k++)
				dp[k + p[i][j]] = max(dp[k + p[i][j]], dp[k] + p[i + 1][j] - p[i][j]);
		x += dp[x];
	}
	cout << x << endl;
}

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

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

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

  int ret = 0;
  for(int i = 1; i <= N; ++i) {
    if (to_string(i).length() % 2 == 1) ++ret;
  }

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

cnt = 0
shift = 0
for i in range(n):
  if(a[cnt+shift]==cnt+1):
    cnt+=1
  else:
    shift+=1

if(cnt==0):
  print(-1)
  exit()

print(shift)
    



Measured memory_bytes: 26140
n,l = gets.split.map(&:to_i)
ans = 500
l -= 1
ar = []
y = nil
1.upto(n){|i|
  x = i+l
  ar << x
  if (x.abs) < ans
    ans = x.abs
    y = x
  end
}
if y < 0
  ans *= -1
end
puts ar.inject(:+) - ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fore(i,a,b) for(int i = a; i < b; i++)
using namespace std;
typedef long long ll;

const int MXN = 301;
int A[MXN][MXN], N, M;
int cnt[MXN], idx[MXN];
bool can(int v){
  memset(cnt,0,sizeof(cnt));
  memset(idx,0,sizeof(idx));
  map<int,vector<int> > m;
  set<pair<int,int> > s;
  fore(x,0,N){
    s.erase({-cnt[A[x][0]],A[x][0]});
    cnt[A[x][0]]++; idx[x]++;
    s.insert({-cnt[A[x][0]],A[x][0]});
  }
  while(!s.empty() && -s.begin()->first > v){
    pair<int,int> tmp = *s.begin();
    s.erase(tmp);
    fore(x,0,N) if(A[x][idx[x]-1] == tmp.second){
      if(idx[x] == M) return false;
      s.erase({-cnt[A[x][idx[x]]],A[x][idx[x]]});
      cnt[A[x][idx[x]]]++;
      s.insert({-cnt[A[x][idx[x]]],A[x][idx[x]]});
      idx[x]++;
    }
  }
  return true;
}

int main(){
  cin >> N >> M;
  fore(x,0,N) fore(y,0,M) cin >> A[x][y];
  int low = 0, high = N+1;
  while(high - low > 1){
    int mid=(high+low)/2;
    if(can(mid))
      high = mid;
    else
      low = mid;
  }
  cout << low+1 << "\n";
}


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

array<string, 4> judge = {
    "AC",
    "WA",
    "TLE",
    "RE"
};

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

    map<string, int> m;
    for(int i = 0; i < 4; i++) {
        m.insert(make_pair(judge[i], 0));
    }
    for(int i = 0; i < n; i++) {
        cin >> s;
        m[s] += 1;
    }

    for(int i = 0; i < 4; i++) {
        cout << judge[i] << " x " << m[judge[i]] << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int N = 100+10;
int n;
struct node{
	int mark;
	string name;
	int num;
};
int cmp(node a,node b) {
	if(a.name!=b.name) {
		return a.name<b.name;
	} else {
		return a.mark>b.mark;
	}
}
node p[N];
int main() {
	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>p[i].name>>p[i].mark;
		p[i].num=i+1;
	}
	sort(p,p+n,cmp);
	for(int i=0;i<n;i++) {
		cout<<p[i].num<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());




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

    
   	int n, m;
   	cin >> n >> m;
   	if (n % 2) {
   		fi(0, m) 
   			cout << i + 1 << ' ' << n - i << '\n';
   	} else {
   		int cnt = 0;
   		int a = 1;
   		int b = n;
   		while (cnt < m) {
   			if (b - a == n / 2)
   				--b;
   			cout << a << ' ' << b << '\n';
   			if (b - a ==  n / 2 + 1)
   				--b;
   			++a;
   			--b;
   			++cnt;
   		}
   	}
}

Measured memory_bytes: 3628