akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(void){
    int n;
    cin >> n;
    priority_queue<int> pq;
    int oddnum=0; 
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(a%2==1){oddnum++;}
        pq.push(a%2);
    }

    if(oddnum%2==1){cout << "NO" << endl;}
    else{cout << "YES" << endl;}
    
    /*以下勘違いしたもの
    while(!pq.empty()){
        pq.pop();
        if(pq.empty()){cout << "No" << endl; return
        pq.pop();
        pq.push(0);
    }

    cout << "Yes" << endl;
    return 0;
    */
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#define ll long long

using namespace std;

const long long mod = 1e9+7;

int main(){
    int n, m, l ,r;
    cin >> n >> m;

    int maxL, minR;
    maxL = 1;
    minR = n;
    for(int i = 0; i < m; i++){
        cin >> l >> r;
        if(maxL < l) maxL = l;
        if(minR > r) minR = r;
    }

    if(minR < maxL) cout << 0 << endl;
    else cout << minR - maxL + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int r = s.length()-1;
    if (s[r] ==  '2'|| s[r] == '4' || s[r] == '5' || s[r] == '7' || s[r] == '9') cout <<"hon";
    else if ( s[r] == '0'|| s[r] == '1' || s[r] == '6' || s[r] == '8') cout << "pon";
    else cout <<"bon";
    return 0;
}


Measured memory_bytes: 3604
using System;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int X_cand = (int)(N / 1.08);

        int X = (int)(X_cand * 1.08);
        if (X == N)
            Console.WriteLine(X_cand);
        else
        {
            int X_cand2 = (int)((X_cand+1) * 1.08);
            if(X_cand2 == N)
                Console.WriteLine(X_cand + 1);
            else
                Console.WriteLine(":(");
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define ff first
#define ss second
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
#define d(a,b,c) cout<<a<<" "<<b<<" "<<c<<'\n'
#define IO ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define mem(a, b) memset(a,b,sizeof(a))

int main()
{
    ll n, k; cin >> n >> k;
    int a[n+1];
    for(int i = 1, x; i <= n; i++)
    {
        cin >> x; a[i] = x;
    }
    ll tm[n+1];
    for(int i = 0; i <= n; i++)
        tm[i] = -1;
    ll i = 1, cnt = 0;
    while(tm[i] == -1)
    {
        tm[i] = cnt;
        if(cnt == k)
        {
            cout << i << endl;
            return 0;
        }
        i = a[i];
        cnt++;
    }
    cnt -= tm[i];
    k -= tm[i];
    k %= cnt;
    for(ll j = 0; j < k; j++)
        i = a[i];
    cout << i << endl;

    return 0;
}












Measured memory_bytes: 5968
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<bool> so(n*400, true);
    so[1] = false;
    for(int i=2; i<n*400; i++){
        if(so[i]){
            //cout << i << endl;
            for(int j=2; j<(n*400-1)/i+1; j++){
                so[i*j] = false;
            }
        }
    }
    int count = 0;
    for(int i=2; i<n*400; i++){
        if(so[i] and i%5==1){
            count += 1;
            if(count == n){
                cout << i << endl;
                break;
            }else{
                cout << i << " ";
            }
        }
    }

}

Measured memory_bytes: 256
#include <stdio.h>
int main (void){
 char s[12];
char t[13];
int i;
scanf("%s",s);
for(i=0;i<13;i++){
if(i<4) t[i]=s[i];
else if (i==4) t[i]=' ';
else t[i]=s[i-1];
}
for(i=0;i<13;i++){
printf("%c",t[i]);
}
printf("\n");
return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
    string Taro, Hanako;
    int n;
    int Tscore = 0; 
    int Hscore = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> Taro >> Hanako;
        if(Taro > Hanako){
            Tscore += 3;
        } else if(Taro == Hanako){
            Tscore += 1;
            Hscore += 1;
        } else {
            Hscore += 3;
        }
    }
    cout << Tscore << " " << Hscore << endl;
    return 0;
}


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

int main()
{
    int r;
    cin>>r;
    cout<<r*r<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();

		String[] s = new String[N];
		int[] t = new int[N];

		for (int i = 0; i < N; i++) {
			s[i] = sc.next();
			t[i] = sc.nextInt();
		}

		String X = sc.next();

		sc.close();

		int ans = 0;
		boolean b = false; // ねてる=true
		for (int i = 0; i < N; i++) {
			if (b) {
				ans += t[i];
			}
			if (s[i].equals(X)) {
				b = true;
			}
		}

		out.println(ans);

	}

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


Measured memory_bytes: 25044
#include <stdio.h>
#include <math.h>
#define FLOOR_HEIGHT 5

int checkBrokened(int y, double border){
	double t;
	double maxV;
	t = sqrt(y /4.9); 
	maxV = 9.8 * t;
	if(maxV >= border){return 1;}	
	return 0;
}

int main(void){
	int i;
	int h;
	double border;
	while(1){
		if(scanf("%lf",&border) == EOF){break;}
		for(i = 1; ; i++){
			h = FLOOR_HEIGHT * (i-1);
			if(checkBrokened(h,border)){break;}
		}
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int i,j;
    int n;
    cin >> n;
    int a,b;
    cin >> a >> b;
    vi x,y,z;
    vi in(n);
    rep(i,n) cin >> in[i];
    rep(i,n){
        if(in[i] <= a)x.push_back(i);
        else if(in[i] <= b)y.push_back(i);
        else z.push_back(i);
    }
    //cout << x.size() << " " << y.size() << " " << z.size() << endl;
    int ans = min(x.size(), min(y.size(),z.size()));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T> void rd(T &t) {
	char ch=getchar(); t=0; int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9');
	t*=f;
}
const int maxn=30;
typedef long long ll;
const ll mod=(1e9)+7;
int n,m,S,T,sz;
bool flag,e[maxn][maxn];
char s[maxn][maxn];
bool u[maxn],ok[maxn];
int xs[maxn];
ll h1[maxn],h2[maxn],cf[maxn];
int d[maxn],d2[maxn],c[maxn][30];
void print() {
	for (int i=1;i<=m;i++)
			printf("%d ",d2[i]);
		printf("\n");
}
void dfs(int x2) {
	if (x2>m) {
		for (int i=1;i<=n;i++) {
			h1[i]=h2[i]=0;
			for (int j=1;j<=m;j++) {
				h1[i]+=cf[j]*(s[i][d[j]]-'a'+1)%mod; h1[i]%=mod;
				h2[i]+=cf[m-j+1]*(s[i][d[j]]-'a'+1)%mod; h2[i]%=mod;
			}
		}
		memset(ok,0,sizeof(ok));
		int cnt=0;
		for (int i=1;i<=n;i++) {
			if (ok[i]) continue;
			for (int j=1;j<=n;j++)
				if (h1[i]==h2[j]&&!ok[j]) {
					if (i==j) {
						cnt++;
						if (n%2==0||(n%2==1&&cnt>1)) continue;
					}
					ok[i]=ok[j]=1; break;
				}
			if (!ok[i]) return;
		}
		flag=1;
		//print();
		return;
	}
	int x=xs[x2];
	for (int i=1;i<=m;i++)
		if (!u[i]) {
			if (!e[d2[m-x+1]][i]) continue;
			u[i]=1;
			//print();
			d[i]=x; d2[x]=i;
			dfs(x2+1);
			if (flag) return;
			u[i]=0; d2[x]=d[i]=0;
		}
}
// 5 12 3 11 8 6 7 9 4 10 2 1
int main() {
	//freopen("1.txt","r",stdin);
	rd(n); rd(m);
	for (int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	cf[0]=1;
	for (int i=1;i<=m;i++)
		cf[i]=(cf[i-1]*27)%mod;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			c[j][s[i][j]-'a'+1]++;
	memset(e,1,sizeof(e));
	for (int i=1;i<=m;i++)
		for (int j=1;j<=m;j++) {
			for (int k=1;k<=26;k++)
				if (c[i][k]!=c[j][k]) {
					e[i][j]=0; break;
				}
		}
	for (int i=1;i*2<=m;i++) {
		xs[++sz]=i; xs[++sz]=m-i+1;
	}
	if (sz!=m) xs[++sz]=m/2+1;
	/*for (int i=1;i<=sz;i++)
		printf("%d ",xs[i]);
	printf("\n");*/
	dfs(1);
	if (!flag) printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

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

    std::vector<int> A;
    for (size_t i = 0; i < N; ++i) {
        int t;
        std::cin >> t;
        A.push_back(t);
    }


    constexpr std::pair<int, int> range[] =
    {{1,399},
     {400,799},
     {800,1199},
     {1200,1599},
     {1600,1999},
     {2000,2399},
     {2400,2799},
     {2800,3199}};

    int col = 0;
    for (auto&& r: range) {
        auto pos = std::find_if(std::begin(A), std::end(A), [r](int a) {
                return r.first <= a && a <= r.second;
            });
        if (pos != std::end(A)) {
            col++;
        }
    }

    auto n = std::count_if(std::begin(A), std::end(A), [](int a) {
            return 3200 <= a;
        });

    std::cout << std::max(col, 1) << " " << col + n << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a, b;
	cin >> a >> b;

	cout << (b - a) * (1 + b - a) / 2 - b<< endl;

	return 0;
}

Measured memory_bytes: 256
n = input()
l = len(n)
def su(x):
	return sum([int(i) for i in str(x)])
ans = su(n)
for j in range(1,l):
	pre = su(int(n[:j])-1)
	suf = (l-j)*9
	ans = max(ans,pre+suf)
print(ans)


Measured memory_bytes: 2940
#include <stdio.h>
int main(void){
    int cnt,num,i = 0;
    scanf( "%d" , &cnt );
    while( i < cnt ){
        i++;
        num = i;
        while( num ){
            if( num % 10 == 3 || i % 3 == 0 ){
                printf( " %d" , i );
                break;
            }
            num /= 10;
        }
    }
    printf("\n");
}


Measured memory_bytes: 2108
N, M = gets.chop.split.map(&:to_i)
A = gets.chop.split.map(&:to_i)

cum = [0]
(0..N-1).each do |i|
    cum << cum[i] + A[i]
end

cum.map!{ |c| c % M }


hash = {}
cum.each do |c|
    if hash.has_key?(c)
        hash[c] += 1
    else
        hash[c] = 1
    end
end

count = 0
hash.values.each do |v|
    next if v == 1
    count += v * (v - 1) / 2
end
p count

Measured memory_bytes: 13964
#include<iostream>
#include<cmath>
using namespace std;
int n, p, a[4], t, s;

bool prime(int p) {
	for (int i = 2; i*i <= p; i++) {
		if (p%i == 0) {
			return false;
		}
	}
	return true;
}

int main() {
	cin >> n >> p;
	if (p < 0) { for (int i = 0; i < 2 * n; i++) { cout << '9'; }cout << endl; }
	else {
		for (int i = pow(10, n) - 1; i >= 0; i--) {
			s = 0;
			for (int j = 0; j < n; j++) {
				a[j] = (i / (int)pow(10, j)) % 10;
				s += a[j] * (int)pow(10, n - j - 1);
			}
			t = i*pow(10, n + 1) + p*pow(10, n) + s;
			if (prime(t)) { cout << t << endl; break; }
		}
	}
	return 0;
}

Measured memory_bytes: 1204
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**10
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():
    n,k,t,u,v,l = LI()
    d = [I() for _ in range(n)] + [l]
    cd = ck = ct = 0
    r = 0
    for di in d:
        while ct < di and ck > 0:
            ct += t * v
            ck -= 1
        if ct >= di:
            r += (di - cd) / v
        else:
            r += (ct - cd) / v
            r += (di - ct) / u
            ct = di
        ck += 1
        if ck > k:
            ck = k
            ct = di + t * v
        cd = di

    return '{:0.9f}'.format(r)



print(main())



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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

ll memo[87];

ll solve(ll n)
{
  if (memo[n] > 0) return memo[n];
  if (n == 0) return 2;
  if (n == 1) return 1;
  return memo[n]= solve(n - 1) + solve(n - 2);
}

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

  LCIN(N);
  ll ans = solve(N);
  cout << ans << endl;
  
  return 0;
}



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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout<< #i<< "= "<< i << endl
using namespace std;
int perm(int a,int b,int c){
    if(a == b && b == c){
        return 1;
    }else if(a != b && b != c && c != a){
        return 6;
    }else{
        return 3;
    }
}

int calc(int a, int b, int c,int n){
    int k = a*a+b*b+c*c+a*b+b*c+c*a;
    if(k == n) return 1;
    else return 0;
}

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

    FOR(i,1,(n+1)){
        int cnt = 0;
        int f = sqrt(i)+1;
        FORB(j,f,1){
            FORB(k,j,1){
                FORB(l,k,1){
                    cnt += (calc(j,k,l,i)*perm(j,k,l));
                }
            }
        }
        cout << cnt << endl;

    }
}


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

using namespace std;
typedef pair<int, int> PII;

int main() {
    string s;
    cin >> s;
    int n;
    int len = s.size();
    cin >> n;
    vector<pair<int, char> > f;
    for (int i = 1; i <= n; ++i) {
        int op;
        cin >> op;
        if (op == 1) {
            f.emplace_back(1, '0');
        } else {
            int k;
            cin >> k;
            string cur;
            cin >> cur;
            f.emplace_back(k + 1, cur[0]);
        }
    }
    int num = 0;
    for (auto i : f) {
        if (i.first == 1) {
            num++;
            continue;
        }
        if (num % 2 == 0) {
            if (i.first == 2) s.insert(0, 1, i.second);
            else s.push_back(i.second);
        } else {
            if (i.first == 3) s.insert(0, 1, i.second);
            else s.push_back(i.second);
        }
    }
    if (num % 2)
        reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 2928
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int x, a;
	cin >> x >> a;
	if(x < a){
		cout << 0 << endl;
	}else{
		cout << 10 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
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-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

vector<int> g[N];
int was[N];

int dfs(int v) {
  was[v] = 1;
  int res = 1;
  for (int u : g[v]) {
    if (!was[u]) {
      res += dfs(u);
    }
  }
  return res;
}

void solve(int test) {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int v, u;
    cin >> v >> u;
    --v; --u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (!was[i]) {
      ans = max(ans, dfs(i));
    }
  }
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.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: 31736
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	string s;cin>>s;
	string a="AKIHABARA",b="AKIHABAR",c="AKIHABRA",d="AKIHBARA",
	       e="AKIHABR",f="AKIHBAR",g="AKIHBRA",h="AKIHBR",
		   i="KIHABARA",j="KIHABAR",k="KIHABRA",l="KIHBARA",
		   m="KIHABR",n="KIHBAR",o="KIHBRA",p="KIHBR";
	if(s==a||s==b||s==c||s==d||s==e||s==f||s==g||s==h||s==i||
	   s==j||s==k||s==l||s==m||s==n||s==o||s==p){
		   cout<<"YES"<<endl;
	   }
	else cout<<"NO"<<endl;
}

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

int main() {
  int N;
  cin >> N;
  int A = 0;
  
  for (int i = 0; i < N; i++){
    int L,R;
    cin >> L >> R;
    A += R - L + 1;
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
#define ld long double
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];
int Food[100100];

signed main() {
  int N, K; cin >> N >> K;
  vector<int> Input(N);
  vector<int> Food(N);
  rep(i, N) {
    cin >> Input[i];
  }
  rep(i, N) {
    cin >> Food[i];
  }

  sort(Input.begin(), Input.end());
  sort(Food.rbegin(), Food.rend());

  ll r = 1e12; // true
  ll l = -1; // false
  while (l+1 < r) {
    int c = (r + l) / 2;
    
    bool ok = [&](){
                ll s = 0;
                rep(i, N) {
                  s += max(0ll, Input[i]- c/Food[i]);
                }
                return s <= K;
              }();

    if (ok) r = c; else l = c;
  }

  cout << r << endl;
  return 0;
}


Measured memory_bytes: 3328
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vii vector<ii>
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define pin(n) in(n.first) >> n.second
#define vin(a, n) for (ll i=0; i<n; ++i) in(a[i])
#define viin(a, n) for (ll i=0; i<n; ++i) in2(a[i].first, a[i].second);
#define out(n) cout << n
#define outs(n) out(n) << ' '
#define outn(n) out(n) << '\n'
#define out2(n, m) cout << n << ' ' << m
#define out2s(n, m) out2(n, m) << ' '
#define out2n(n, m) out2(n, m) << '\n'
#define pout(n) out2(n.first, n.second)
#define pouts(n) pout(n) << ' '
#define poutn(n) pout(n) << '\n'
#define vout(a) for (auto i : a) outs(i)
#define viout(a) for (auto i : a) out2n(i.first, i.second)
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pp(a, b) emplace_back(make_pair(a, b))
#define fori(i, n) for (ll i=0; i<n; ++i)
#define foris(i, a, b) for (ll i=a; i<b; ++i)
#define ford(i, n) for (ll i=n-1; i>=0; --i)
#define fords(i, a, b) for (ll i=a; i>=b; --i)
#define forr(i, a) for (auto &i : a)
const int mod = (int)(1e9) + 7;
//endregion


int main() {
    io();
    string s;
    int n, total = 0;
    in(s);
    n = s.length();
    stack<char> st;
    fori (i, n) {
        if (!st.empty() && s[i] != st.top()) {
            st.pop();
            total += 2;
        } else {
            st.push(s[i]);
        }
    }
    out(total);
}


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

int main(){
    while(1){
        int n,p;
        int flag=0;
        int have[50];
        //読み込み
        cin>>n>>p;
        int cup = p;
        if(n == 0 && cup==0){
            return 0;
        }

        for(int i=0; i<n; i++){
            have[i]=0;
        }

        for(int i=0;;i=(i+1)%n){
            if(cup==0){
                cup = have[i];
                have[i]=0;
            }else if(cup>0){
                have[i]++;
                cup--;
                if(have[i]==p){
                    cout<<i<<endl;
                    break;
                }
            }
        }
    }
}



Measured memory_bytes: 3092
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define yn(i) print((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }


int main() {
  vector<li> a(2),b(2);
  rep(i,2)cin >>a[i];
  rep(i,2)cin >>b[i];
  li s=a[0]*b[0];
  rep(i,2)rep(j,2) s=max(s,a[i]*b[j]);
  print(s);
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
template<typename T = int> using V = vector<T>;
template<typename T = int> using P = pair<T, T>;
using Vi = V<int>;
using Vl = V<ll>;
using Vd = V<ld>;
using VVi = V<Vi>;
using VVl = V<Vl>;
using VVd = V<Vd>;
using Pi = P<int>;
using Pl = P<ll>;
using Pd = P<ld>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); } // floor(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); } // ceil(log2(x))
inline int popcount(const ll x) { return __builtin_popcountll(x); }
inline void fail() { cout << -1 << '\n'; exit(0); }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
// const int INF  = 1<<30;
// const ll INFll = 1ll<<60;
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


V<V<Pi>> G;
int t;
ll S;

bool dfs(int u, int p=-1) {
  for (auto [v, i] : G[u]) if (v != p) {
    if (v == t || dfs(v, u)) {
      S |= (1ll<<i);
      return true;
    }
  }
  return false;
}


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

  G.assign(n, V<Pi>());
  rep(i, n-1) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].emplace_back(v, i);
    G[v].emplace_back(u, i);
  }

  int m; cin >> m;
  Vl SE(m);
  rep(i, m) {
    int s; cin >> s >> t;
    --s, --t;
    S = 0;
    dfs(s);
    SE[i] = S;
  }

  ll ans = 0;
  rep(T, 1<<m) {
    ll mask = 0;
    rep(i, m) if (T>>i&1) mask |= SE[i];
    ll res = 1ll<<(n-1-popcount(mask));
    if (popcount(T)&1) ans -= res;
    else ans += res;
  }
  cout << ans << '\n';
}



Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int a[11000];

int main(){
  int H,W;
  cin>>H>>W;
  string s[110];
  for(int i=0;i<H;i++) cin>>s[i];

  for(int i=0;i<H;i++){
    cout<<s[i]<<endl;
    cout<<s[i]<<endl;
  }
}


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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}
int main(){
 int  a,b,c,i,x;
  cin>>a>>b>>c>>x;
  i=0;
  REP(A,a+1)REP(B,b+1)REP(C,c+1)
  if(A*500+B*100+C*50==x) i++;
  cout<<i;
 return 0;
}


Measured memory_bytes: 3628
/* AOJ0118 Property Distribution */

#include <iostream>
#include <cstdio>

using namespace std;

#define DIRECTSIZE 4
struct _direct {
    int drow;
    int dcol;
} direct[DIRECTSIZE] =
    {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};

const int N = 100;
string grid[N];
int h, w, ans;

void dfs(int row, int col, char c)
{
    if(grid[row][col] == c) {
        grid[row][col] = ' ';

        int nextrow, nextcol;
        for(int i=0; i<DIRECTSIZE; i++) {
            nextrow = row + direct[i].drow;
            nextcol = col + direct[i].dcol;

            if(0 <= nextrow && nextrow < h && 0 <= nextcol && nextcol < w)
                if(grid[nextrow][nextcol] != ' ')
                    dfs(nextrow, nextcol, c);
        }
    }
}

int main()
{    
    while(cin >> h >> w && (h || w)) {
        getchar();
        for(int i=0; i<h; i++)
            getline(cin, grid[i]);

        ans = 0;
        for(int i=0; i<h; i++)
            for(int j=0; j<w; j++) {
                char c = grid[i][j];
                if(c != ' ') {
                    ans++;
                    dfs(i, j, c);
                }
            }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,m;
   cin>>n>>m;
   vector<string>s(n);
   for(int i=0;i<n;i++)
   {
       cin>>s[i];
   }
   sort(s.begin(),s.end());
   for(int i=0;i<n;i++)
   {
       cout<<s[i];
   }
   cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> lint gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> lint lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, cnt = 0, tmp = 1000000;
  cin >> n;
  vector<int> vec(n);
  rep(i, n) {
    cin >> vec[i];
    if (vec[i] <= tmp) cnt++;
    chmin(tmp, vec[i]);
  }
  cout << cnt << '\n';
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	string S;
	int len;

	cin >> S;
	len = S.length();

	rep(i, len) cout << 'x';
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template<class A> ostream& operator <<(ostream& out, const vector<A> &v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        if(i) out << ", ";
        out << v[i];
    }
    return out << "]";
}

const int maxn = 2005;
LL dp[maxn][maxn];

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

    int n;
    cin >> n;
    vector<int> a(n);
    vector<PII> b;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b.push_back(make_pair(a[i], i));
    }
    LL res = 0;
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++) dp[0][i] = 1LL * b[0].first * abs(i - b[0].second);
    for (int i = 1; i < n; i++) {
        int v = b[i].first, idx = b[i].second;
        for (int j = 0; j + i < n; j++) {
            // left: j, right: j + i
            dp[i][j] = max(dp[i - 1][j] + 1LL * v * abs(j + i - idx), dp[i - 1][j + 1] + 1LL * v * abs(j - idx));
        }
    }
    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < n; j++) {
    //         cout << i << " " << j << " " << dp[i][j] << endl;
    //     }
    // }
    // int left = 0, right = n - 1;
    // for (int i = n - 1; i >= 0; i--) {
    //     int v = b[i].first, idx = b[i].second;
    //     if (abs(left - idx) >= abs(right - idx)) {
    //         res += abs(left - idx) * v;
    //         left++;
    //     } else {
    //         res += abs(right - idx) * v;
    //         right--;
    //     }
    // }
    cout << dp[n - 1][0] << '\n';

    return 0;
}


Measured memory_bytes: 26292
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
int main(){
    boost;
    double l;   cin>>l;
    double ans = pow(l/3, 3);
    printf("%0.7lf", ans);
}

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

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	map<ll,int> mp;
	ll gcd = 0;
	bool flag = false;
	rep(i,n){
		cin >> a[i];
		gcd = __gcd(gcd, a[i]);
		ll temp = a[i];
		if(!flag){
			for (ll j = 2; j*j <= temp; ++j) {
				if(temp % j) continue;
				mp[j]++;
				if(mp[j] >= 2) {
					flag = true;
					break;
				}
				while(temp % j == 0){
					temp /= j;
				}
			}
			if(temp != 1) mp[temp]++;
		}
	}
	
	if(!flag){
		for(auto p: mp){
			if(p.second >= 2) {
				flag = true;
				break;
			}
		}
	}
	if(gcd >= 2){
		cout << "not coprime" << endl;
	} else if (flag){
		cout << "setwise coprime" << endl;
	}else{
		cout << "pairwise coprime" << endl;
	}
    return 0;
}

Measured memory_bytes: 11148
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
    cout.flush();
    cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }


bool check(ll a, ll b, ll c) {
    return c < a + b;
}

int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);


    ll n;
    cin >> n;
    vl a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(all(a));

    ll ans = 0;
    for (ll i = 0; i < n; ++i) {
        for (ll j = i + 1; j < n - 1; ++j) {
            ll l = a[j] - a[i] + 1;
            ll r = a[j] + a[i] - 1;
            ans += lower_bound(a.begin() + j + 1, a.end(), r + 1) - lower_bound(a.begin() + j + 1, a.end(), l);
        }
    }
    cout << ans << endl;

    print_time();
    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = tuple(int(x) for x in input().split())

    memo = tuple([0] * n for _ in range(n))
    for i in range(n):
        memo[i][i] = a[i]

    for l in range(n - 2, -1, -1):
        for r in range(l + 1, n):
            memo[l][r] = max(a[l] - memo[l + 1][r], a[r] - memo[l][r - 1])

    print(memo[0][n - 1])


if __name__ == '__main__':
    main()

# [l,r]を
# l:=配列aの右端から左にシフト
# r:=lと一致する位置からn-1まで右にシフト
# と考えると、l==rは既にメモ化済みなので、l=n-2以前、r=l+1以降を調べればよい
# 漸化式で使う値は、
# lがより右にいるときの計算結果（前のループで計算済み）と
# rがより左にいるときの計算結果（一番左でもl==rなので計算済み）
# なので、参照する値がNoneになることはなく、Noneのチェックは不要になる

# Noneではなく、0で初期化する


Measured memory_bytes: 112092
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

int n, m, l;
void solve() {
	vector<int> b(n);
	rep(i, n) {
		cin >> b[i]; b[i]--;
	}
	vector<ll> a(m);
	vector<ll> ra(m+1,0);
	rep(i, m)cin >> a[i];
	rep(i, m) {
		ra[i + 1] = ra[i] + a[i];
	}
	sort(b.begin(), b.end());
	vector<vector<ll>> dp(n);
	rep(i, n) {
		dp[i].resize(n, INF);
	}
	dp[0][0] = 0;
	rep1(i, n - 2) {
		rep(j, i) {
			ll cost = dp[i - 1][j] + (ra[b[i] + 1] - ra[b[j]]) / l;
			dp[i][i - 1] = min(dp[i][i - 1], cost);
			cost = dp[i - 1][j] + (ra[b[i]+1] - ra[b[i - 1]]) / l;
			dp[i][j] = min(dp[i][j], cost);
		}
	}
	ll ans = INF;
	rep(j, n - 1) {
		ll cost = dp[n - 2][j];
		cost += (ra[b[n - 1]+1] - ra[b[n - 2]]) / l;
		cost += (ra[b[n - 1] + 1] - ra[b[j]]) / l;
		ans = min(ans, cost);
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	while (cin >> n>>m>>l, n) {
		solve();
		break;
	}
	//solve();
	//stop
	return 0;
}


Measured memory_bytes: 35888
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, h, m, r, a;
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%02d:%02d", &h, &m); r = h * 60 + m; m *= 12;
		a = min(abs(r - m), 720 - abs(r - m));
		if(a < 60) printf("alert\n");
		else if(a < 180) printf("warning\n");
		else printf("safe\n");
	}
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  string s;cin>>s;
  cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
  return 0;
}

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

void solve() {
    int h, a;
    cin >> h >> a;
    cout << (h - 1) / a + 1 << endl;
    return;
}

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


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {

	var x1, x2, y1, y2 float64

	fmt.Scan(&x1, &y1, &x2, &y2)

	fmt.Println(math.Sqrt(math.Pow(x1-x2, 2) + math.Pow(y1-y2, 2)))

}



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

int main(){

	  int N,W; cin >> N >> W;
	  int w[N+1],v[N+1];
	  for(int i=1; i<N+1; i++)
			cin >> v[i] >> w[i];


	  
	  int dp[N+1][W+1] = {};

	  for(int i=1; i<N+1; i++){
			for(int j=0; j<W+1; j++){
				  dp[i][j] = max(dp[i-1][j],dp[i][j]);
				  if(j-w[i] < 0) continue;
				  dp[i][j] = max(dp[i][j-w[i]] + v[i], dp[i][j]);
			}
	  }
	  int ans=0;
	  for(int j=0;j<W+1;j++) ans = max(ans, dp[N][j]);
	  cout << ans << endl;
	  
}

Measured memory_bytes: 7008
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
    int k, x; cin >> k >> x;
    set<int> s;
    for (int i = -1000000; i <= 1000000; i++) {
        if (abs(x - i) < k) s.emplace(i);
    }
    vector<int> v;
    for (int si: s) v.emplace_back(si);
    for (int i = 0; i < v.size(); i++) cout << v[i] << " \n"[i == v.size() - 1];
    return 0;
}

Measured memory_bytes: 256
use proconio::input;
 
fn main() {
  input! {
    n: usize,
    k: usize,
    vals: [isize;n]
  }
  
  if n-1 <= k {
    println!("{}", (vals[n-1] - vals[0]).abs());
    return
  };
  
  let mut dp: Vec<isize> = vec![isize::max_value();n];
  for i in 0..=k {
    dp[i] = (vals[i] - vals[0]).abs();
  }

  for i in k+1..n {    
    for ii in 1..=k {
      dp[i] = std::cmp::min(
        (vals[i]-vals[i-ii]).abs() + dp[i-ii],
        dp[i]
      );
    }
  }
  
  println!("{}", dp[n-1]);
}

Measured memory_bytes: 4028
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

long double distance(long double x1, long double y1, long double x2, long double y2);

int main () {
    // input
    long double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    // solve
    long double d;
    d = distance(x1, y1, x2, y2);

    // output
    cout << fixed;
    cout << setprecision(5) << d << endl;
}

long double distance(long double x1, long double y1, long double x2, long double y2) {
    long double d;
    d = sqrt( pow(x1-x2, 2) + pow(y1-y2, 2) );
    return d;
}


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

const int INF = 500000005;

int main(){
  int n;
  cin>>n;
  vector<pair<int,int>> a(n);
  rep(i,n){
    int x,l;
    cin>>x>>l;
    a[i].first = x-l;
    a[i].second = x+l;
  }
  
  sort(a.begin(),a.end());
  int ans = n;
  
  rep(i,n-1){
    if(a[i].second>a[i+1].first){
      ans--;
      if(a[i].second<a[i+1].second){
        a[i+1].second = a[i].second;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> k;
  ans = 1;
  rep(i, n) {
    ans *= k;
    ans %= MOD;
  }
  Cout(ans);
  return 0;
}


Measured memory_bytes: 3232
import math
n, k = map(int, input().split())

if k == 1:
    print(n**3)
    exit()
if n == 1:
    print(1*(k==3))
    exit()
    
ans = 0
for i in range(n):
    a = i+1
    if 2*(i+1) % k == 0:
        lb = math.floor((a%k)/k)
        if a%k == 0:
            lb = 1
        ub = math.floor((n-a%k)/k)
        # print(a, (a%k)/k, (n-a%k)/k)
        ans += (ub-lb+1)**2
print(ans)


Measured memory_bytes: 9200