akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    rep(i, H) cin >> S[i];

    vector<int> wcnt, tmp, idx(H);
    int ans = INF;
    rep(bit, 0, 1 << (H - 1)) {
        int k = 0;
        for (int i = 0; i < H; ++i) {
            idx[i] = k;
            if (bit >> i & 1) k++;
        }
        wcnt.assign(k + 1, 0);
        tmp.assign(k + 1, 0);
        int sum = 0;
        rep(j, W) {
            fill(all(tmp), 0);
            rep(i, H) tmp[idx[i]] += S[i][j] == '1';
            bool ok = true;
            rep(l, k + 1) {
                if (tmp[l] > K) ok = false;
            }
            if (!ok) {
                sum = INF;
                break;
            }
            bool sep = false;
            rep(l, k + 1) {
                if (wcnt[l] + tmp[l] > K) sep = true;
            }
            if (sep) {
                sum++;
                rep(l, k + 1) wcnt[l] = tmp[l];
            }
            else {
                rep(l, k + 1) wcnt[l] += tmp[l];
            }
        }
        ans = min(ans, k + sum);
    }
    write(ans);
}

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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1e18+1;

signed main() {
	int n, w, h;
	cin >> n >> w >> h;
	int imosw[100010] = {0};
	int imosh[100010] = {0};

	for ( int i = 0; i < n; i++ ) {
		int a, b, c;
		cin >> a >> b >> c;
		imosw[max(0LL, a-c)]++;
		imosw[min(w, a+c)]--;
		imosh[max(0LL, b-c)]++;
		imosh[min(h, b+c)]--;
	}

	for ( int i = 1; i < 100005; i++ ) {
		imosw[i] = imosw[i]+imosw[i-1];
		imosh[i] = imosh[i]+imosh[i-1];
	}
	
	bool flag = true;
	for ( int i = 0; i < h; i++ ) {
		if ( imosh[i] == 0 ) flag = false;
		//cout << imosh[i] << " ";
	}
	//cout << endl;
	if ( flag ) {
		cout << "Yes" << endl;
		return 0;
	}
	flag = true;
	for ( int i = 0; i < w; i++ ) {
		if ( imosw[i] == 0 ) flag = false;
	}
	if ( flag ) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 4660
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner sc=new Scanner(System.in);
		
		//数列の長さ
		int N=sc.nextInt();
		//各数字の数値
		ArrayList<Integer>numberArrayList=new ArrayList<>();
		
		for(int i=0;i<N;i++) {
			numberArrayList.add(sc.nextInt());
		}
		
		ArrayList<Integer>culculationNumber=new ArrayList<>(numberArrayList);
		Collections.sort(culculationNumber,Collections.reverseOrder());
		int max=Collections.max(culculationNumber);
		
		
		for(int i=0;i<N;i++) {
			if(max==numberArrayList.get(i)) {
				System.out.println(culculationNumber.get(1));
			}else {
				System.out.println(max);
			}
			
		}
	}

}


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

int main() {
  long long n;
  cin>>n;
  long long a[2001];
  for(int i=0;i<2001;i++){
    a[i]=pow(i-1000,5);
  }
  long long s,t;
  bool b=false;
  for(int i=0;i<2000;i++){
    for(int j=i;j<2001;j++){
      if(a[j]-a[i]==n){
        s=j;
        t=i;
        b=true;
        break;
      }
    }
    if(b)break;
  }
  cout<<s-1000<<' '<<t-1000<<endl;
}


Measured memory_bytes: 4112
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  cin >> n >> m;
  int s = 0, mn = inf;
  for (int i = 1; i <= n; ++i) {
    s += m + i - 1;
    if (abs(mn) > abs(m + i - 1)) {
      mn = m + i - 1;
    }
  }
  cout << s - mn << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    char a[6];
    for(int i=0;i<6;i++)cin>>a[i];
    if(a[0]==a[5]&&a[1]==a[4]&&a[2]==a[3])cout<<"YES";
    else cout<<"NO";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
st = []
for i in range(n):
  s, t = input().split()
  st.append((s, int(t)))
x = input()

ans, f = 0, 0
for s, t in st:
  if f:
    ans += t
  if s == x:
    f = 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int A,B,C;
main(){
  cin>>A>>B>>C;
  vector<int>xs={A,B,C};
  sort(xs.begin(),xs.end());
  string s=xs==vector<int>({5, 5, 7})?"YES":"NO";
  cout<<s<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;

string A,B;
int main (){
    cin >> A >> B;
    int a = A.length();
    int b = B.length();
    if (a > b) cout << "GREATER" << endl;
    else if (b > a) cout << "LESS" << endl;
    else {
        for(int i=0; i<a; i++){
            if ( A[i] > B[i] ) {
                cout << "GREATER" << endl;
                return 0;
            } else if( A[i] < B[i]){
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
        return 0;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = ReadIntArray();
            var b = ReadIntArray();
            var c = ReadIntArray();
            var result = b.Sum();
            for (int i = 1; i < n; i++)
            {
                if (a[i - 1] == a[i] - 1)
                {
                    result += c[a[i - 1] - 1];
                }
            }
            Console.WriteLine(result);
        }

        public static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
    }
}


Measured memory_bytes: 13396
n = gets.chomp.to_i
ary = gets.chomp.split.map(&:to_i)

def find_non_zero_range(ary)
  s = ary.index(&:nonzero?)
  if s
    e = (ary[(s + 1)..-1].index(&:zero?) + s) rescue (ary.size - 1)
    return s..e
  else # all zero
    return nil
  end
end

ans = 0
loop do
  target_rng = find_non_zero_range(ary) || break
  min = ary[target_rng].min
  target_rng.each do |i|
    ary[i] = ary[i] - min
  end
  ans += min
end
puts ans

Measured memory_bytes: 14288
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
t=SI()
n=len(s)
u=len(t)
mx=-1
for i in range(n-u+1):
    count=0
    for j in range(u):
        #print(s[i+j])
        if s[i+j]==t[j] or s[i+j]=="?":
            count+=1
    if count==u:
        mx=i
#print(mx)
if mx<0:
    print("UNRESTORABLE")
else:
    for i in range(mx):
        if s[i]=="?":
            print("a",end="")
        else:
            print(s[i],end="")
    print(t,end="")
    for i in range(mx+u,n):
        if s[i]=="?":
            print("a",end="")
        else:
            print(s[i],end="")

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

int main() {
    int A = 0, B = 0 ,N ;
    cin >> N ;
    vector<int> card(N) ;
    for(int i = 0; i < N ; i++){
        cin >> card.at(i);
    }
    sort(card.begin(), card.end());
    reverse(card.begin() , card.end());
    for(int i = 0 ; i < N ; i++){
        if(i % 2 == 0){
            A += card.at(i);
        }
        else{B += card.at(i);}
    }
    cout << A - B << endl;
    }


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

using namespace std;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
const int INF = 1 << 30;

typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    int b = 0;
    while(A[i] % 2 == 0) {
      A[i] /= 2;
      b++;
    }
    ans += b;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

map<char, int>mp;
signed main() {
	string s;
	cin >> s;
	rep(i, s.size()) {
		mp[s[i]]++;
	}
	if (((!mp['N'] && !mp['S']) || (mp['N'] && mp['S'])) && ((!mp['W'] && !mp['E']) || (mp['W'] && mp['E']))) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	endre;
}

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long )(1e18+1)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');
    cerr.write(names, name-names) << " = " << arg1 << endl;
    _F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){
    in >> q.F >> q.S; return in;
}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}
template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}
template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}


void solve(){
    int n, w;
    cin >> n >> w;
    int dp[n+1][w+1];
    int W[n+1], V[n+1];
    for(int i = 1; i <= n; i++){
        cin >> W[i] >> V[i];
    }
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= w; j++){
            dp[i][j] = dp[i-1][j];
            if(j >= W[i])
                dp[i][j] = max(dp[i][j], dp[i-1][j-W[i]]+V[i]);
            dp[i][j] = max(dp[i][j], dp[i][j-1]);
        }
        //cout << dp[i][n] << endl;
    }
    cout << dp[n][w] << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(12);

    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    //freopen("error.txt", "w", stderr);
    //#endif

    //cin >> t;

    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": "; 
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}

Measured memory_bytes: 79232
#include "bits/stdc++.h"
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF   = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

void solve()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int K;
    cin >> K;

    vector<LL> A(X);
    REP0 (i, X)
    {
        cin >> A[i];
    }

    vector<LL> B(Y);
    REP0 (i, Y)
    {
        cin >> B[i];
    }

    vector<LL> C(Z);
    REP0 (i, Z)
    {
        cin >> C[i];
    }

    vector<LL> E;
    REP0 (i, X)
    {
        REP0 (j, Y)
        {
            E.push_back(A[i] + B[j]);
        }
    }

    sort(E.begin(), E.end(), [](LL a, LL b) { return a > b; });
    sort(C.begin(), C.end(), [](LL a, LL b) { return a > b; });

    vector<LL> ans;

    REP0 (i, min(X * Y, K))
    {
        REP0 (j, min(Z, K))
        {
            ans.push_back(E[i] + C[j]);
        }
    }

    sort(ans.begin(), ans.end(), [](LL a, LL b) { return a > b; });

    REP0 (i, K)
    {
        cout << ans[i] << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 42856
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]

bh=[0]*n
c=[0]*n
for i,s in enumerate(f):
  for j,h in enumerate(s):
    bh[i]|=h<<j

maxp=-float('inf')
for mbh in range(1,2**10):
  for i in range(n):
    intsect=mbh&bh[i]
    c[i]=sum(intsect>>k&1 for k in range(10))
  maxp=max(maxp,sum(p[i][c[i]] for i in range(n)))
print(maxp)

Measured memory_bytes: 9152
n, m = map(int, input().split())

a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
ans = "No"

for i in range(n - m + 1): #列のシフト分
    for j in range(n - m + 1): #行のシフト分
        for k in range(m): #bの列番号
            if b[k] != a[i + k][j:j + m]:
                break
            if k == m - 1 and b[k] == a[i + k][j:j + m]:
                ans = "Yes"

print(ans)

Measured memory_bytes: 3064
n = gets.to_s.to_i

memo = Array.new(n + 1){|i| Array.new(n + 1){|j| i.gcd(j) }}

ans = 0
1.upto(n) do |i|
  1.upto(n) do |j|
    t = memo[i][j]
    if 1 == t
      ans += n
      next
    end
    1.upto(n) do |k|
      ans += memo[t][k]
    end
  end
end
 
puts ans

Measured memory_bytes: 14328
#include<bits/stdc++.h>
#define llong __int128
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

map<llong,llong> mp;
llong n,A,B,C,D;

void read128(__int128 &x) {long long y; scanf("%lld",&y); x = y;}

llong absl(llong x) {return x<0?-x:x;}

void updmin(llong &x,llong y) {x = min(x,y);}

void dfs(llong x)
{
	if(mp.count(x)) {return;}
	llong ret = x*D,t;
	t = x/2ll; dfs(t); updmin(ret,mp[x/2ll]+min((x-x/2ll)*D,A+(x%2ll)*D));
	t = (x+1)/2ll; dfs(t); updmin(ret,mp[(x+1)/2ll]+min((x-(x+1ll)/2ll)*D,A+(2ll-x%2ll)%2ll*D));
	t = x/3ll; dfs(t); updmin(ret,mp[x/3ll]+min((x-x/3ll)*D,B+(x%3ll)*D));
	t = (x+2)/3ll; dfs(t); updmin(ret,mp[(x+2)/3ll]+min((x-(x+2ll)/3ll)*D,B+(3ll-x%3ll)%3ll*D));
	t = x/5ll; dfs(t); updmin(ret,mp[x/5ll]+min((x-x/5ll)*D,C+(x%5ll)*D));
	t = (x+4)/5ll; dfs(t); updmin(ret,mp[(x+4)/5ll]+min((x-(x+4ll)/5ll)*D,C+(5ll-x%5ll)%5ll*D));
	mp[x] = ret;
	return;
}

int main()
{
	int T = read(); while(T--)
	{
		read128(n),read128(A),read128(B),read128(C),read128(D);
		mp.clear(); mp[0] = 0ll; mp[1] = D;
		dfs(n);
		printf("%lld\n",(long long)mp[n]);
	}
	return 0;
}

Measured memory_bytes: 4740
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f():
        a = LI()
        while a[-1] != 0:
            a += LI()
        r = [[]]
        c = 0
        nk = [a[0]]
        d = {}
        d[0] = 0
        for n in a[1:]:
            if n == 0:
                break
            while nk[d[c]] < 1:
                c -= 1

            if n < 0:
                dc = d[c]
                dn = d[c+n]
                r[dn].append(dc)
                r[dc].append(dn)
                nk[dn] -= 1
                nk[dc] -= 1
            else:
                nk.append(n-1)
                dc = d[c]
                ni = len(nk) - 1
                r[dc].append(ni)
                r.append([dc])
                nk[dc] -= 1
                c += 1
                d[c] = ni
        rr = []
        for i in range(len(nk)):
            rr.append('{} {}'.format(i+1, ' '.join(map(lambda x: str(x+1), sorted(r[i])))))
        return '\n'.join(rr)

    while 1:
        n = I()
        if n == 0:
            break
        rr = [f() for _ in range(n)]
        break

    return '\n'.join(map(str, rr))


print(main())



Measured memory_bytes: 9124
#include <iostream>

using namespace std;

int main()
{
    int N,num[100];
    int ddata;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>num[i];
    }
    int j;
    cout<<num[0];
    for(j=1;j<N;j++){
        cout<<" "<<num[j];
    }
    cout<<endl;
    for(int i=1;i<N;i++){
        ddata=num[i];
        j=i-1;
        while(j>=0&&num[j]>ddata){
            num[j+1]=num[j];
            j--;
        }
        num[j+1]=ddata;
        cout<<num[0];
        for(j=1;j<N;j++){
            cout<<" "<<num[j];
        }
        cout<<endl;
    }
    
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll n,m,s,t;
vector<ll> dijkstra(vector<vector<P>>& g, ll sp) {
	vector<ll> dir(n,INF*INF);
	dir[sp]=0;
	priority_queue<P,vector<P>,greater<P>> q;
	q.push(P(0,sp));
	while(!q.empty()) {
		ll d=q.top().first;
		ll p=q.top().second;
		q.pop();
		if(dir[p]!=d) continue;
		REP(i,g[p].size()) {
			ll np=g[p][i].first;
			ll cost=g[p][i].second;
			if(dir[np]>d+cost) {
				dir[np]=d+cost;
				q.push(P(dir[np],np));
			}
		}
	}
	return dir;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n>>m>>s>>t;
	s--; t--;
	vector<vector<P>> gy(n);
	vector<vector<P>> gs(n);
	REP(i,m) {
		ll u,v,a,b;
		cin>>u>>v>>a>>b;
		u--;
		v--;
		gy[u].pb(P(v,a));
		gy[v].pb(P(u,a));
		gs[u].pb(P(v,b));
		gs[v].pb(P(u,b));
	}
	vector<ll> ycost=dijkstra(gy,s);
	vector<ll> scost=dijkstra(gs,t);
	const ll init=1000000000000000LL;
	priority_queue<P,vector<P>,greater<P>> q;
	REP(i,n) {
		q.push(P(ycost[i]+scost[i],i));
	}
	REP(i,n) {
		while(q.top().second<i) {
			q.pop();
		}
		cout<<init-q.top().first<<endl;
	}
}


Measured memory_bytes: 19836
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, i, k, h[100001], ans=0;
    cin >> n >> k;
    for(i=0;i<n;i++){
        cin >> h[i];
    }
    for(i=0;i<n;i++){
        if(h[i]>=k) ans++;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n; cin>>n;
    vector <int> a(n); 
    
    rep(i,n) {cin>>a[i]; if(a[i] == 0) {cout<<0<<endl; return 0;}};
    int ans = 114514;
    
    sort(a.begin(),a.end());
    map <int,int> ma;
    rep(i,n){
        ma[a[i]]++;
    }
    rep(i,13) if(ma[i]>=3) {cout<<0<<endl; return 0;}
    rep(i,n){
        if(i%2 == 0) a[i] = 24-a[i];
    }
    //rep(i,n) cout<<a[i]<<endl;
    a.push_back(0);
    rep(i,n+1) rep(j,n+1){
        if(i==j) continue;
        ans = min(ans, abs(a[i]-a[j]));
    }
    rep(i,n){
        ans = min(ans, min(a[i], 24-a[i]));
    }
    cout<<ans<<endl;
}


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

int main(){
  vector<int> x(5);
  int k;
  for(int i=0;i<5;i++){
    cin>>x.at(i);
  }
  cin>>k;
  sort(x.begin(),x.end());
  if(x.at(4)-x.at(0)<=k){
    cout<<"Yay!"<<endl;
  }else{
    cout<<":("<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include <forward_list>
#include <numeric>

#define mod 1000000007

using namespace std;


int main() {

	int n;

	cin >> n;

	vector<int> p(n);

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

	int count = 0;
	for (int i = 1; i < n-1; i++) {

		if (p[i] >= p[i - 1] && p[i] < p[i + 1])
			count++;
		else if (p[i] < p[i - 1] && p[i] >= p[i + 1])
			count++;

	}

	cout << count;

	return 0;
}




Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	H = inputInt()
	W = inputInt()
	N = inputInt()

	ans = 0
	tmp = max(H,W)
	#print(tmp)
	ans = -(-N // tmp)

	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <climits>
#include <cassert>
#include <iterator>

using namespace std;
using ll = long long;

bool ok(int a, int b, int c){
    return a+b>c && b+c>a && a+c>b;
}

int main(){
    int tests;
    // cin >> tests;
    tests = 1;
    while(tests--){
        ll x,k,d;
        cin >> x >> k >> d;
        x = abs(x);
        
        ll full = x / d;
        x = x - (min(full, k) * d);
        k -= min(full, k);
        
        k = k & 1;
        cout << (k == 1ll ? abs(d - x) : x) << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll, ll>P;
const ll mod = 1e9 + 7;
const int INF = 1000000;
const double PI = 3.14159265359;


int main() {

	int n; cin >> n;
	int p[n]; rep(i, 0, n)cin >> p[i];
	int mi = 1e6, ma = 0;

	int ans = 0;
	rep(i, 0, n) {
		if (mi > p[i]) {
			ans++;
			mi = p[i];
		}
		else if (ma > p[i]) {
			ans++;
			ma = p[i];
		}
		
	}
	out(ans);



	return 0;
}


Measured memory_bytes: 1024
import sys
import math 
from collections import deque

n,m,k=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a=[0]
b=[0]

for i in range(n):
    a.append(A[i]+a[i])
for i in range(m):
    b.append(B[i]+b[i])

ans,j=0,m

for i in range(n+1):
    if a[i] > k :
        break
    while b[j] > k-a[i] : 
        j-=1
    ans = max(ans, i+j)

print(ans)



Measured memory_bytes: 47780
#include <stdio.h>

int main() {

int n,k,i,j=1;

scanf("%d%d",&n,&k);

if(n>=1&&k<=10){

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

	if(j>k){j+=k;}

	else if(j<=j){   j*=2;

			}

}

printf("%d\n",j);

}

return 0;

}

Measured memory_bytes: 1700
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main(void) {
    int N;
    string S, T;
    string ans;
    
    cin >> N;
    cin >> S >> T;
    
    for (int i = 0; i < N; i ++) {
        ans += S[i];
        ans += T[i];
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let r: usize = iterator.next().unwrap().parse().unwrap();
    let c: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();
    let mut map: Vec<Vec<usize>> = vec![vec![0; c]; r];
    for _ in 0..k {
        let ri: usize = iterator.next().unwrap().parse().unwrap();
        let ci: usize = iterator.next().unwrap().parse().unwrap();
        let vi: usize = iterator.next().unwrap().parse().unwrap();
        map[ri - 1][ci - 1] = vi;
    }

    let mut dp: Vec<Vec<Vec<usize>>> = vec![vec![vec![0; 4]; 3005]; 3005];
    for i in 0..r {
        for j in 0..c {
            for k in (0..3).rev() {
                dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + map[i][j]);
            }
            for k in 0..4 {
                dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
                dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
            }
        }
    }

    let mut ans = 0;
    for k in 0..4 {
        ans = max(ans, dp[r - 1][c - 1][k]);
    }
    ans.to_string()
}


Measured memory_bytes: 710956
#include <iostream>

using namespace std;


int main(){
   int i,j;
   cin >> i;
   if(i >= 0 && i <= 86400){
       cout << i / 3600  << ":" << (i % 3600) / 60 << ":" << (i % 3600) % 60 << endl;
   }else{
       return -1;
   }

   return 0;
}


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

Int mod_pow(Int x,Int y,Int mod){
  Int res = 1;
  while(y){
    if(y&1) res = res * x % mod;
    x = x * x % mod;
    y /= 2;
  }
  return res;
}

Int extgcd(Int a,Int b,Int &x,Int &y){
  Int d = a;
  if(b != 0){
    d = extgcd(b, a%b, y,x);
    y -= (a/b) * x;
  } else{
    x = 1, y = 0;
  }
  return d;
}

Int mod_inverse(Int a,Int mod){
  Int x,y;
  extgcd(a,mod,x,y);
  return (mod+x%mod)%mod;
}

const Int MOD = 1e6+3;
const Int MAX_P = 200000;
Int fact[MAX_P],inv[MAX_P],finv[MAX_P];
  
void init(Int mod){
  fact[0] = 1;
  for(Int i=1;i<MAX_P;i++)
    fact[i] = (fact[i-1]*i)%mod;

    inv[1] = 1;
    for(Int i=2;i<MAX_P;i++)
      inv[i] = inv[mod%i]*(mod-mod/i)%mod;

    
    finv[0] = 1;
    for(Int i=1;i<MAX_P;i++)
      finv[i] = finv[i-1] * inv[i]%mod;
}

Int mod_comb3(Int n,Int k,Int mod){
  if(k < 0|| k > n) return 0;
  return fact[n] * finv[k] % mod * finv[n-k]%mod;
}

const Int MAX = 2020;
vector<vector<Int> > ds(MAX);

Int dp[MAX][MAX];
Int memo[MAX][MAX];

Int dfs(Int p,Int n){
  Int &res=memo[p][n];
  if(~res) return res;

  res=dp[p][n];
 
  for(Int l:ds[n]){
    Int a=(n/l);
    if(p%a) continue;
    res+=MOD-dfs(p/a,l)*(p/a)%MOD;
  }
  
  res%=MOD;
  res*=mod_inverse(p,MOD);
  res%=MOD;
  return res;
}

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  for(Int i=1;i<MAX;i++)
    for(Int j=i+i;j<MAX;j+=i)
      ds[j].emplace_back(i);

  init(MOD);
  
  Int n,k;
  while(cin>>n>>k,n||k){

    vector<Int> co(MAX,0);
    for(Int i=1;i<=k;i++)
      for(Int j=1;j<=k;j++)
	co[i+j]++;
    
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(Int p=0;p<n;p++){
      for(Int i=0;i<=n;i++){
	dp[p][i]%=MOD;
	//cout<<p<<":"<<i<<":"<<dp[p][i]<<endl;
	if(!dp[p][i]) continue;       
	for(Int a=2;i+a<=n;a++){
	  dp[p+1][i+a]+=dp[p][i]*co[a]%MOD;
	}
      }
    }
    
    memset(memo,-1,sizeof(memo));
    Int ans=0;
    for(Int i=0;i<=n;i++) dfs(i,n);
    if(n<=k) ans+=2;
    
    for(Int p=0;p<=n;p++)
      for(Int i=0;i<=n;i++)
	if(~memo[p][i]) ans+=memo[p][i];
    
    ans%=MOD;
    cout<<ans<<endl;
  }
  
  return 0;
}




Measured memory_bytes: 71904
N=int(input())
cher=[0]*26
ans_list=[]
flag=True

cher[0]='z'
count=1
for i in 'abcdefghijklmnopqrstuvwxy':
    cher[count]=i
    count+=1

while N>26:
    if N%26==0:
        ans_list.append(cher[N%26])
        N-=1
        N=N//26
    else:
        ans_list.append(cher[N%26])
        N=N//26
ans_list.append(cher[N%26])
print(''.join(ans_list)[::-1])

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

const long long mod=1000000007;

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int s[n],t[m];
	for (int i = 0; i < n; ++i)
	{
		cin>>s[i];
	}
	for (int i = 0; i < m; ++i)
	{
		cin>>t[i];
	}
	long long dp[n+5][m+5]={};
	for (int i = 0; i < n+5; ++i)
	{
		dp[i][0]=1;
	}
	for (int i = 0; i < m+5; ++i)
	{
		dp[0][i]=1;
	}
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
			dp[i][j]%=mod;
			if (s[i-1]!=t[j-1])
			{
				dp[i][j]-=dp[i-1][j-1];
				dp[i][j]%=mod;
			}
		}
	}
	dp[n][m]+=mod;
	dp[n][m]%=mod;
	cout<<dp[n][m]<<endl;
	return 0;
}


Measured memory_bytes: 31616
N, M = map(int, input().split())

ll = 0
rr = int(10e5+1)
for _ in range(M):
    l, r = map(int, input().split())
    ll = max(ll, l)
    rr = min(rr, r)
if rr - ll + 1 <= 0:
    print(0)
else:
    print(rr - ll + 1)

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

int main() {
    string s;
    cin >> s;
    vector<int> arr(26, 0);
    for(char c: s)
        arr[c-'a'] += 1;
    for(int i = 0; i < 26; i++)
    if (arr[i] == 0) {
        cout << char('a'+i) << endl;
        return 0;
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 3720
import java.util.*;

public class Main{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    //整数の入力
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    //これらの分け方が等しくなりうるかを判別する


    //出力
    isDivision(a, b, c);
  }
  static void isDivision(int a, int b, int c){
    if((a+b) == c || (a+c) == b || (b+c) == a){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }

}


Measured memory_bytes: 9044
import sys

def main():
    sys.stdin.readline()
    numbers = [int(i) for i in sys.stdin.readline().strip().split()]
    current = 1
    for i in numbers:
        if current < i:
            current = i -1
        elif current > i:
            print("No")
            return
    print("Yes")
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 14396
import scala.io.StdIn.readLine

object Main {
  val N = 1000000007

  def multi(m:Long, n:Long) = { ( (m%N) * (n%N) ) % N }

  def pow(m:Long, n:Long, b1:Long, b2:Long, b3:Long):Long = {
    n match {
      case 0 => 1
      case 1 => multi(b1,b3)
      case _ =>
        val c = b2 match {
          case 1 => m % N
          case _ => multi(b2,b2)
        }
        pow(m, n/2, multi(b1,b1), c, (if (n%2==0) 1 else c) * (b3 % N))
    }
  }

  def main(args: Array[String]) = {
    val l = readLine().split(" ").map(_.toLong)
    val (m,n) = (l(0),l(1))
    println(pow(m,n,m,1,1))
  }
}

Measured memory_bytes: 43776
N = gets.to_i
ps = gets.chomp.split.map(&:to_i)

dp = Array.new(N, 10000)

dp[0] = 0
dp[1] = (ps[0] - ps[1]).abs
for i in 2..(N - 1)
  dp[i] = [dp[i -1] + (ps[i - 1] - ps[i]).abs, dp[i - 2] + (ps[i - 2] - ps[i]).abs].min
end

puts dp[N-1]


Measured memory_bytes: 11780
n = int(input())
p = list(map(int, input().split()))
p = [(x-1, i+1) for i, x in enumerate(p)]
p.sort()

a = [0]*n
b = [0]*n

for i, j in p:
    a[i] = (n+1)*i+1
    b[i] = (n+1)*(n-i)+j

f = lambda x: " ".join(list(map(lambda n: str(n), x)))
print(f(a))
print(f(b))


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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    int _min, _max;
    long long int _sum;
    _min = a[0];
    _max = a[0];
    _sum = 0;
    rep(i, n) {
        if (a[i] < _min) _min = a[i];
        if (_max < a[i]) _max = a[i];
        _sum += a[i];
    }
    printf("%d %d %lld\n", _min, _max, _sum);
    return 0;
}


Measured memory_bytes: 3184
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces1196E
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a,a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ll x, ll y, ll a, ll b){ return sqrt((x - a)*(x - a) + (y - b)*(y - b)); }
void debug(bool* a, ll n) { for ( int k = 0; k < n; k++ ){ cout << a[k] << " ";} cerr << "\n"; }

const ll mod = 1000000007;

int main(){
	FASTIO;
	string s; cin >> s;
	ll n = s.length();
	ll dp[n][13]; memset(dp, 0, sizeof dp);
	if (s[0] == '?') {
		for ( int k = 0; k < 10; k++ ){ dp[0][k] = 1; }
	}else dp[0][s[0] - '0'] = 1;
	for ( int k = 1; k < n; k++ ){
		ll temp = s[k] - '0';
		if (s[k] == '?') {
			for ( int i = 0; i < 10; i++ ){
				temp = i;
				for ( int j = 0; j < 13; j++ ){
					dp[k][(j * 10 + temp)%13] += dp[k - 1][j];
					dp[k][(j * 10 + temp)%13] %= mod;
				}
			}
		}else {
			for ( int j = 0; j < 13; j++ ){
				dp[k][(j * 10 + temp)%13] += dp[k - 1][j];
				dp[k][(j * 10 + temp)%13] %= mod;
			}
		}
	}
	cout << dp[n - 1][5] << endl;
	return 0;
}

Measured memory_bytes: 10704
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;
int main()
{
    ll q;
    cin>>n;
    ll sum=0;
    ll arr[n+10],brr[n+10],crr[n+10];
    arr[0]=-1;
    FOR1(i,n)cin>>arr[i];
    FOR1(i,n)cin>>brr[i];
    FOR1(i,n-1)cin>>crr[i];
    FOR1(i,n)
    {
        ll x=arr[i];
        ll y=arr[i-1];
        sum+=(brr[arr[i]]);
        if(x-y==1)
        {
            sum+=crr[arr[i-1]];
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

using namespace std;

int main(){
    int N, a[200000], max, max_2, i, n;
    cin >> N;

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

    max = a[0];
    max_2 = 0;
    n = 0;  //maxが複数あるかの確認用

    for (i = 0; i < N-1; i++) {
      if (max < a[i+1]) {
        max_2 = max;
        max = a[i+1];
        n = 0;
      } else if(max == a[i+1]){
        max_2 = a[i];  //これいらないか。
        n++;
      }else if(max_2 < a[i+1]){
        max_2 = a[i+1];
      }
    }

//出力
    if (n > 0) {
      for (i = 0; i < N; i++) {
        cout << max << endl;
      }
    }else{
      for (i = 0; i < N; i++) {
        if (a[i] < max) {
          cout << max << endl;
        } else {
          cout << max_2 << endl;
        }
      }
    }

    return 0;
}


Measured memory_bytes: 2432
#include <cstdio>
#include <algorithm>
typedef long long ll;

int n,a[105];
ll Ans;

void DFS(int p)
{

    if(p==n+1)
    {
        ll Sum=0;
        for(int i=1;i<=n;++i)Sum+=a[i];
        Ans=std::max(Ans,Sum);
        return;
    }
    if(a[p]<0)
    {
        int b[105];
        for(int i=1;i<=n;++i)b[i]=a[i];
        for(int i=p;i<=n;i+=p)a[i]=0;
        DFS(p+1);
        for(int i=1;i<=n;++i)a[i]=b[i];
    }
    DFS(p+1);
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]);
    for(int i=n;i>n/6;--i)
    {
        ll Sum=0;
        for(int j=i;j<=n;j+=i)Sum+=a[j];
        if(Sum<=0)for(int j=i;j<=n;j+=i)a[j]=0;
    }
    DFS(1),printf("%lld\n",Ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int n, k;
int a[108], b[108];
vector<int> ans;
int cnt[108];

int main(){
  cin >> n >> k;
  for(int i = 0;i < n;i++)cin >> a[i], b[i] = a[i];
  vector<int> ans;
  int last = -1;
  for(int i = 0;i <= k;i++){
    int minid = -1;
    for(int j = 0;j < n;j++){
      if(j == last)continue;
      if(minid == -1 || a[minid] > a[j]){
	if(minid != -1)ans.push_back(minid + 1);
	cnt[minid]++;
	minid = j;
      }
      else{
	ans.push_back(j+1);
	cnt[j]++;
      }
    }
    ans.push_back(minid+1);
    cnt[minid]++;
    a[minid]++;
    last = minid;
    //    cout << i << " " << minid << endl;
  }
  for(int i = 0;i < n;i++){
    if(b[i] < cnt[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans.size() << endl;
  for(int i = ans.size() - 1;i >= 0;i--)cout << ans[i] << " ";cout << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np

# n,k = map(int, input().split())

h = int(input())
# h = list(map(int,input().split()))
ans = 0
b = 1
while h > 0:
    ans += b
    b *= 2
    h //= 2

print(ans)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class162
    {
        static void Main()
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NM[0], M = NM[1];
            int count = 0;
            int a = 0, b = 0;
            if (N >= 2) a = (N * (N - 1)) / 2;
            if (M >= 2) b = (M * (M - 1)) / 2;
            Console.WriteLine(a + b);
        }
    }
}


Measured memory_bytes: 13268
#!/usr/bin/env python
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

odd = [x for (i, x) in enumerate(v) if i % 2 == 1]
even = [x for (i, x) in enumerate(v) if i % 2 == 0]

odd_c = Counter(odd)
even_c = Counter(even)

odd_c = sorted(odd_c.items(), key=lambda x: x[1], reverse=True) + [(-1, 0)]
even_c = sorted(even_c.items(), key=lambda x: x[1], reverse=True) + [(-1, 0)]

if odd_c[0][0] != even_c[0][0]:
    print(n - odd_c[0][1] - even_c[0][1])
elif odd_c[0][1] + even_c[1][1] >= odd_c[1][1] + even_c[0][1]:
    print(n - odd_c[0][1] - even_c[1][1])
else:
    print(n - odd_c[1][1] - even_c[0][1])


Measured memory_bytes: 19032
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
//    String s=sc.next();
    int x=sc.nextInt();
    int a=sc.nextInt();
    int b=sc.nextInt();
    System.out.println(x+a>=b?"Yes":"No");
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"

#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0);}

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

    long long q,h,s,d;
    cin >> q >> h >> s >> d;
    h = min(h, 2 * q);
    s = min(s, 2 * h);
    d = min(d, 2 * s);
    long long n;
    cin >> n;
    long long ans = n / 2 * d;
    ans += (n & 1) * s;
    cout << ans << endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(all(l));
    int sum = 0;
    rep(i,n-1) sum += l[i];
    if(sum > l[n-1]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

bool could[100010];
int balls[100010];

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

	memset(could, 0, sizeof(could));
	
	int n, m; cin >> n >> m;
	forn(i,n) { could[i + 1] = 0, balls[i + 1] = 1; }
	could[1] = 1;
	
	while (m--) {
		int x, y; cin >> x >> y;
		
		//~ could[y] |= could[x];
		if (could[x]) could[y] = true;
		balls[y]++;
		balls[x]--;
		if (balls[x] == 0) could[x] = false;
		//~ could[x] &= balls[x];
	}
	
	int res = 0;
	forn(i, n) res += could[i + 1];
	
	cout << res << endl;
}


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

int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  string ans = "No";
  while(c>0 && a>0) {
    c -= b;
    a -= d;
    if (c <= 0) ans = "Yes";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[n];
    int dp[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        if(abs(a[i]-a[i-1])+dp[i-1]<=abs(a[i]-a[i-2])+dp[i-2])
        dp[i]=abs(a[i]-a[i-1]) + dp[i-1];
        else
        dp[i]=abs(a[i]-a[i-2]) + dp[i-2];
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024