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

int main() {
  
  long long N, M;
  cin >> N >> M;
  
  
  multimap<long long, long long> AB;
  multimap<long long, long long>::iterator p;
  
  vector<long long> A(N), B(N);
  for(long long i=0; i<N; i++){ 
    cin >> A[i];
    cin >> B[i];
    AB.insert(pair<long long, long long>(A[i], B[i]));
//    AB[A[i]] = B[i];
  }
  
  long long num=0;
  long long cost=0;
  
  for(p = AB.begin(); p != AB.end(); p++){
    if(num+(p->second)<M){
      cost += (p->first)*(p->second);
      num+=p->second;
    }
    else{
      long long nokori = M-num;
      cost += (p->first)*nokori;
      break;
    }
  }
  
  cout << cost << endl;
  

}



Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int M, K, t;

int main() {
	cin >> M >> K;
	if (M == 1) {
		if (K) {
			cout << -1 << endl;
		}
		else {
			cout << 0 << sp << 0 << sp << 1 << sp << 1 << endl;
		}
	}
	else {
		if ((1 << M) > K) {
			cout << K << sp;
			for (int i = 0; i < (1 << M); ++i) {
				if (i == K)continue;
				cout << i << sp;
			}
			cout << K << sp;
			for (int i = (1 << M) - 1; i >= 0; --i) {
				if (i == K)continue;
				cout << i << sp;
			}
			cout << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
}

Measured memory_bytes: 1792
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

ll power(int m, int n){
    if(n == 0) return 1;
    
    if(n % 2 == 0){
        ll tmp = power(m , n / 2);
        return tmp * tmp % INF;
    }
    return  power(m , n - 1) * m % INF;
}

int main(){
    int m, n;
    cin >> m >> n;
    cout << power(m, n) << endl;
}


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

int a[110][110];

int main() {
  int n, k;
  cin >> n >> k;
  map<int, int>mp;
  rep(i,k){
    int d;
    cin >> d;
    rep(j,d){
      cin >> a[i][j];
      mp[a[i][j]]++;
    }
  }
  cout << n-mp.size() << endl;
  return 0;
}


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

int main(){
int b,c;
cin>>b>>c;
long long a;
vector<long long>arr;
for(int i=0;i<b;i++){
    cin>>a;
    arr.push_back(a);
}
sort(arr.begin(),arr.end());
reverse(arr.begin(),arr.end());
long long s=0;
if(c>arr.size())
    c=arr.size();
if(c<=arr.size()-1){
for(int i=c;i<arr.size();i++){
    s+=arr[i];
}}
cout<<s<<endl;
}


Measured memory_bytes: 2420
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
       int n;cin>>n;
       VEC(int,d,n);
       int res = 0;
       for(int i=0;i<n;i++){
           for(int j=i+1;j<n;j++){
               res += (d[i]*d[j]);
           }
       }
       cout<<res;
    }
    


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B,C=MI()
    print(C,A,B)
if __name__ == '__main__':
    main()

Measured memory_bytes: 66540
h,w=[int(x) for x in input().split()]
if h%3==0 or w%3==0:
    s=0
elif h==1 or w==1:
    s=1
else:
    s=float("inf")
    def diff(a,b):
        shen=b//2
        tmpS=float("inf")
        for i in range(1,a):
            p1=i*b
            hen=(a-i)//2
            p2=hen*b
            p3=(a-hen-i)*b
            q2=(a-i)*shen
            q3=(a-i)*(b-shen)
            tmpS=min(tmpS,max(p1,p2,p3)-min(p1,p2,p3),max(p1,q2,q3)-min(p1,q2,q3))
        return tmpS
    s=min(diff(h,w),diff(w,h))
print(s)

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

int main(){
  int N,M;
  cin>>N>>M;
  int T=100*(N-M)+1900*M;
  int num=1;
  for(int i=0;i<M;i++){
    num*=2;
  }
  cout<<num*T<<endl;
}


Measured memory_bytes: 256
from itertools import permutations
N, W, R = map(int, input().split())
S = list(map(int, input().split()))

INFTY = 10**9
cost = [[INFTY]*(N+1) for _ in range(N+1)]

# 辺を入力
for _ in range(W):
    u, v, c = map(int, input().split())
    cost[u][v] = c
    cost[v][u] = c

# 自身に向かうコストは0
for i in range(N+1):
    cost[i][i] = 0


def WarshallFloyd():
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j])


WarshallFloyd()

ans = 10**9
for T in permutations(S, R):
    temp = 0
    t = T[0]
    for i in range(1, R):
        temp += cost[t][T[i]]
        t = T[i]
    ans = min(ans, temp)
print(ans)


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

typedef unsigned long long ull;
unsigned long long m[44]={0};


ull fib(int n) {
  if(m[n]!=0){
    return m[n];
  }
  if(n==0||n==1){
    m[n]=1;
    return 1;
  }else{
    m[n]=fib(n-1)+fib(n-2);
    return m[n];
  }
}

int main(void) {
  int n;
  cin >> n;
  cout << fib(n) << endl;
  return 0;
}

Measured memory_bytes: 3108
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class EOrPlusMax {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      int s = 1<<n;
      vector<int> a(s);
      rep(i, s) {
        cin >> a[i];
      }
      vector<multiset<int>> st(s);
      rep(i, s) {
        st[i].insert(a[i]);
      }
      rep(k, n) {
        rep(i, s) {
          int j = i|(1<<k);
          if (i == j) continue;
          for(auto& e: st[i]) {
            st[j].insert(e);
          }
          auto it = st[j].begin();
          while(st[j].size() > 2) {
            it = st[j].erase(it);
          }
        }
      }

      int ans = 0;
      for(int i=1; i<s; i++) {
        int now = 0;
        for(auto& e: st[i]) {
          now += e;
        }
        chmax(ans, now);
        cout << ans << '\n';
      }
    }
};

signed main() {
  EOrPlusMax solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 40960
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int c[1000001];

void run(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i],c[a[i]]++;
    int m=*max_element(all(a));
    bool p=true;
    REP(i,2,m){
        int t=0;
        for(int j=i;j<=m;j+=i)t+=c[j];
        p&=t<=1;
    }
    if(p){
        cout<<"pairwise coprime"<<endl;
        return;
    }
    int g=a[0];
    rep(i,n)g=gcd(g,a[i]);
    cout<<(g==1?"setwise":"not")<<" coprime"<<endl;
}

Measured memory_bytes: 18528
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  ll ret = 1e18;
  ll c = 0;
  while(true){
    int a = max(0LL, X - (c/2));
    int b = max(0LL, Y - (c/2));

    ret = min(ret, A*a + B*b + C*c);

    if(a==0 && b==0) break;
    c++;
  }

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


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

#define ll long long
#define mp make_pair
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

typedef pair<int, int> pii;
typedef double db;
const int N = 1e6 + 50;
int n, k, a[N], ans = 0, cnt;
set<int> s;
set<int>::iterator it;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
void init() {
  n = read();
  k = read();
  rep(i, 1, n) a[i] = read();
  rep(i, 1, k) s.insert(a[i]);
  rep(i, 2, n) {
    if (a[i] > a[i - 1]) {
      int sum = 0;
      while (a[i] > a[i - 1] && i <= n) i++, sum++;
      if (sum >= k - 1) cnt++;
    }
  }
  ans = n - k + 1;
  int l = 1, r = k;
  while (l <= r && r <= n) {
    r++;
    if (r > n) break;
    s.insert(a[r]);
    if (*(s.rbegin()) == a[r] && (*s.begin()) == a[l]) ans--;
    s.erase(a[l]);
    l++;
  }
  if (!cnt)
    printf("%d\n", ans);
  else
    printf("%d\n", ans - cnt + 1);
}
int main() {
  init();
  return 0;
}


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

int main() {
  string S,T;
  cin >> S >> T;

  for(int i=0;i<S.size();i++){
    if(S.at(i) != T.at(i)){
      cout << "No" << endl;
      return 0;
    }else continue;
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3596
//#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define bql 2147483647
#define ll long long
#define ull unsigned long long
using namespace std::tr1;
using namespace std;
const int N=2e5+5;
const int mod=998244353;
const int fx[5]={0,-1,0,1,0};
const int fy[5]={0,0,-1,0,1};
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0' && ch<='9'){x=(x<<3)+(x<<1);x+=(ch-'0');ch=getchar();}
    return x*f;
}

void write(int x)
{
    if (x<0) putchar('-'),x=-x;
    if (x>10) write(x/10);
    putchar(x%10+'0');
}

int main()
{
  fast;
  int n,k;
  cin>>n>>k;
  if (n==0)
  {
  	cout<<1<<endl;
  	return 0;
  }
  for (int i=0;;i++)
      if (n<pow(k,i))
      {
      	cout<<i<<endl;
      	return 0;
      }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
using namespace std;
struct Node{
	int key;
	Node *right, *left, *parent;
};
Node *root, *NIL;

Node *find(Node *u, int k){
	while(u!=NIL && k!=u->key){
		if(k<u->key)	u=u->left;
		else	u=u->right;
	}
	return u;
}
void insert(int k){
	Node *y=NIL;
	Node *x=root;
	Node *z;
	z=(Node *)malloc(sizeof(Node));
	z->key=k;
	z->left=NIL;
	z->right=NIL;

	while(x!=NIL){
		y=x;
		if(z->key < x->key){
			x=x->left;
		}
		else
			x=x->right;
	}
	z->parent=y;
	if(y==NIL){
		root=z;
	}else{
		if(z->key < y->key){
			y->left=z;
		}else{
			y->right=z;
		}
	}
}
void inorder(Node *u){
	if(u==NIL)	return ;
	inorder(u->left);
	cout<<" "<<u->key;
	inorder(u->right);
}
void preorder(Node *u){
	if(u==NIL)	return ;
	cout<<" "<<u->key;
	preorder(u->left);
	preorder(u->right);
}
int main(){
	int n, i, x;
	string com;
	cin>>n;
	while(n--){
		cin>>com;
		if(com=="insert"){
			cin>>x;
			insert(x);
		}
		else if(com=="print"){
			inorder(root);
			cout<<endl;
			preorder(root);
			cout<<endl;
		}
		else if(com=="find"){
			cin>>x;
			Node *t=find(root, x);
			if(t!=NIL)	cout<<"yes"<<endl;
			else	cout<<"no"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 21764
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

bool fc(vector<tuple<ll, int, int>> &vt, ll k, ll m){
  int n = vt.size();
  rep(i, n){
    ll t;
    int a, f;
    tie(t, a, f) = vt.at(i);
    if(t <= m) continue;
    int ad = m/f;
    int d = a - ad;
    k -= d;
    if(k < 0) return false;
  }
  return true;
}

int main(){
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(snip_i, n) cin >> a.at(snip_i);
  vector<int> f(n);
  rep(snip_i, n) cin >> f.at(snip_i);
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  vector<tuple<ll, int, int>> vt(n);
  rep(i, n){
    vt.at(i) = make_tuple((ll)a.at(i)*f.at(i), a.at(i), f.at(i));
  }
  ll ng = -1, ok = 1e18+5;
  while(ok-ng>1){
    ll mid = (ok+ng)/2;
    if(fc(vt, k, mid) == true) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
  return 0;
}

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

int main(){
  int N;
  cin  >> N;
  vector<int64_t> v(N);
  for(int i=0;i<N;i++){
    cin >> v.at(i);
    v.at(i)-=(i+1);
  }
  int64_t sump=0;
  int64_t countp=0;
  int64_t summ=0;
  int64_t countm=0;
  int64_t countz=0;
  for(int i=0;i<N;i++){
    if(v.at(i)<0){
      summ-=v.at(i);
      countm++;
    }else if(v.at(i)>0){
      sump+=v.at(i);
      countp++;
    }else{
      countz++;
    }
  }
  int64_t ans=sump+summ;
  if(countp==countm){
    cout << ans << endl;
    return 0;
  }
  if(countm>countp){
    for(int i=0;i<N;i++){
      v.at(i)=-v.at(i);
    }
    swap(countp,countm);
  }
  sort(v.begin(),v.end());
  countm+=countz;
  int prev=0;
  int diff;
  for(int i=0;i<N;i++){
    if(v.at(i)>0){
      diff=v.at(i)-prev;
      sump-=diff*countp;
      summ+=diff*countm;
      ans=min(ans,sump+summ);
      countp--;
      countm++;
      prev=v.at(i);
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()

ll gcd(ll a, ll b){
   if(b == 0) return a;
   
   return gcd(b, a % b);
}

ll sum(int n){
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}
using namespace std;


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

   int n, l; 
   cin >> n >> l;
   vector<string> sma;
   while(n--) {
      string s;
      cin >> s;
      //sort(all(s));
      sma.pb(s);
   }  
   
   string ans = "";
   sort(all(sma));
   for(string s : sma){
      ans += s;
   }

   cout << ans;
   return 0;
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    string s, t;
    cin >> s >> t;
    t.pop_back();
    cout << (s == t ? "Yes" : "No") << newl;

    return 0;
}

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

int main(){
 int h,mh;
 string m;

 while(1){
  cin >> m ;
  if(m=="-")break;
  cin >> h ;
  for(int i=0;i<h;i++){
   cin >> mh ;
   m=m.substr(mh)+m.substr(0,mh);
  }
  cout << m << endl ;
 }

 return 0;
}

Measured memory_bytes: 3156
input1 = gets
input2 = gets
input3 = gets
input4 = gets
num1 = input1.to_i - 1
num2 = 0
for num in 0..num1 do

  if input2[num] == input3[num] && input2[num] == input4[num] && input3[num] == input4[num]then
  elsif input2[num] != input3[num] && input2[num] != input4[num] && input3[num] != input4[num]then
      num2 += 2
  else  input2[num] == input3[num] || input3[num] == input4[num]
    num2 += 1
  end
end
puts num2.to_s


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

int N, K;

int main(){
  cin >> N >> K;
  vector<int> V(N, 0);
  
  for(int i = 0; i < N; i++){
    cin >> V[i];
  }
  
  int ans = 0;
  int lim1 = min(N, K);
  for(int i = 0; i <= lim1; i++){
    for(int j = 0; i + j <= lim1; j++){
      if(i + j == 0) continue;
      vector<int> hav;
      for(int k = 0; k < i; k++){
        hav.emplace_back(V[k]);
      }
      for(int k = 0; k < j; k++){
        hav.emplace_back(V[N - k - 1]);
      }
      sort(hav.begin(), hav.end());
      int tmp = accumulate(hav.begin(), hav.end(), 0);
      int lim2 = min(K - i - j, i + j);
      for(int k = 0; k < lim2; k++){
        if(hav[k] < 0)
          tmp -= hav[k];
        else break;
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
<?php
list($n, $a, $b) = explode(" ", trim(fgets(STDIN)));
$c = 0;
for($i = 1; $i <= $n; $i++){
    $d = digitSum($i);
    if($d >= $a && $d <= $b){
        $c += $i;
    }
}
echo $c;
function digitSum($n){
    if($n < 10)return $n;
    return digitSum(floor($n / 10)) + $n % 10;
}

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


Measured memory_bytes: 1024
#include<iostream>

using namespace std;
int main()
{
	int n,p[15],max = -1,ans = 0;
	cin >> n;
	for(int i=0; i<n;i ++){
		cin >> p[i];
		ans += p[i];
		if(max < p[i])
			max = p[i];
	}
	ans -= max / 2;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
a,b=map(int, input().split())
min = b*10
max = (b+1)*10
flag = True
for i in range (min, max):
  if a*100/8 <= i and i < (a+1)*100/8:
    print(i)
    flag = False
    break
    
if flag:
  print(-1)
 

Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>
using namespace std;
int p;
int N,K;
int square(int a,int i){
  p=min(2*a,a+K);
  if(i==N) return p;
  square(p,++i);
}
int main(){
  scanf("%d %d",&N,&K);
  square(1,1);
  printf("%d\n",p);
  return 0;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;
#define INF 1e9
int N, K;
vector<int> D(10,1);

int dfs(int sum, int depth){
  if(sum >= N){
    return sum;
  }
  int ans = INF;
  REP(i, 10){
    if(depth == 0 && i==0)
      continue;
    if(D[i]){
      ans = min(ans,dfs(sum*10+i, depth+1));
    }
  }
  return ans;
}

int main(){
  cin >> N >> K;
  REP(i, K){
    int d;
    cin >> d;
    D[d] = 0;
  }

  cout << dfs(0,0) << endl;
  return 0;
}

Measured memory_bytes: 256
limit, *ary = gets.split.map(&:to_i)

between = ary.first..ary.last
total_sum = 0

1.upto(limit) do |n|
  ary = n.to_s.chars.map(&:to_i)
  between.include?(ary.inject(:+)) && total_sum += n
end

p total_sum


Measured memory_bytes: 1788
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
using Graph =vector<vector<int>>;

vector<string> data(10000);

int dfs(string s,int n,int depth){
  int max=0;
  for(int i=0;i<depth+1;i++){
    if(max<s[i]){
      max=s[i];
    }
  }
  depth++;
  if(depth==n){
    data.push_back(s);
    cout<<s<<endl;
    return 0;
  }
  for(int i=0;i<max-'a'+2;i++){
    string tmp=s;
    char tmp1='a'+i;
    tmp.push_back(tmp1);
    dfs(tmp,n,depth);
  }
  return 0;
}


int main(){
  int n;cin>>n;
  string s="a";
  dfs(s,n,0);
}

Measured memory_bytes: 5776
from collections import Counter
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
C = Counter(A)
V = [C[k] for k in C]
V.sort()
if(len(V) <= K):
    print(0)
else:
    print(sum(V[:len(V)-K]))


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

#define pb      push_back
#define all(v)  v.begin(),v.end()
#define endl    "\n"
#define FAST    ios_base::sync_with_stdio(0);cin.tie(0);

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

const int    inf = 2e9;
const ll     INF = 4e17;
const int    mod = 1e9+7;
const double eps = 1e-9;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if((b-a)&1) cout << "Borys\n";
	else cout << "Alice\n";
	return 0;
}



Measured memory_bytes: 256
import java.util.*;


class Main{

    Main(){
        Scanner sc = new Scanner(System.in);
        
        int x=sc.nextInt(),y=sc.nextInt();
        int ans=0;
        
        for(int i=0;i<x;i++){
            for(int j=0;j<y;j++){
                ans++;
            }
        }
            
        System.out.println(ans);
    }
    
    public static void main(String[] args){
        new Main();
    }
}

Measured memory_bytes: 17356
A, B = map(int, input().split())
ans = 0
for i in range(A, B + 1):
    para = True
    for j in range(len(str(i))//2):
        if str(i)[j] != str(i)[-j - 1]:
            para = False
            break
    if para:
        ans += 1
print(ans)


Measured memory_bytes: 2940
#include<stdio.h>

int main() {
  char s[4];
  scanf("%s", s);

  if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3] || s[3] == s[4]) {
    printf("Bad\n");
  } else {
    printf("Good\n");
  }

  return 0;
}


Measured memory_bytes: 128
[h,w] = [int(i) for i in input().split()]
a = []
b = 0
for i in range(h):
    a.append(input())
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            b = b + 1

if b == (h+w)-1:
    print("Possible")
else:
    print("Impossible")


Measured memory_bytes: 3060
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    vector<int> v(3);
    REP(i, 3) cin >> v[i];
    int ans = 0;
    while (!(v[0] == v[1] && v[0] == v[2]))
    {
        sort(v.begin(), v.end());
        if (v[1] == v[2] && ((v[1] - v[0]) >= 2))
        {
            v[0] += 2;
        }
        else
        {
            ++v[0];
            ++v[1];
        }
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (long long i = x; i < n; i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
// using ll = long long;
typedef long long ll;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;

    bool find = false;
    rep(i, b) {
        ll num = a * i;
        ll div = num % b;
        if (div == c) {
            find = true;
            break;
        }
    }

    if (find)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

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

struct Node {
  int key;
  Node *parent;
  Node *left;
  Node *right;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;

  Node *z;
  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->parent = NIL;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}

void preorder(Node *u) {
  if (u == NIL) return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}

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

  for (int i = 0; i < n; i++) {
    string s;
    int k;
    cin >> s;
    if ( s == "insert") {
      cin >> k;
      insert(k);
    } else if (s == "print") {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 26584
#include <iostream>
#include<string>
int main() {
    // insert code here...
    std::string b;
    long long int a,d;
    std::cin>>a>>b;
    long long int c;
    b[1]=b[2];
    b[2]=b[3];
    d=(b[0]-'0')*100+(b[1]-'0')*10+(b[2]-'0');
    c=a*d/100;
    std::cout<<c<<std::endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, b * c, a * d, b * d}) << '\n';
}


Measured memory_bytes: 3648
# B _再提出
n, k = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

naibu = 0
for i in range(n):
    for j in range(i+1, n):
        if A[i] > A[j]:
            naibu += 1
gaibu = 0
A2 = A
for i in range(n):
    for j in range(n):
        if A[i] > A2[j]:
            gaibu += 1

total = naibu*k + gaibu*(k*(k-1)//2)
print(total%mod)

Measured memory_bytes: 41948
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N,D;
    cin >> N >> D;
    lint X[N],Y[N];
    rep(i,N) cin >> X[i] >> Y[i];
    lint ans=0;
    rep(i,N) if(X[i]*X[i]+Y[i]*Y[i]<=D*D) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 6732
require 'pp'
n, k, s = gets.split.map(&:to_i)


ans = Array.new(n, s+1)

if s == 10 ** 9
  ans = Array.new(n, 1)
end

k.times do |kk|
  ans[kk] = s
end

# ans[0] = s

# p ans
puts ans.join(' ')



Measured memory_bytes: 5228
import sys
sys.setrecursionlimit(2 * 10 ** 5)
k = int(input())

r = []

MAX = 3234566667

def dfs(x):
    s = str(x)
    r.append(x)
    last = int(s[-1])
    for i in range(last-1, last+2):
        if 0 <= i <= 9:
            next = int(s + str(i))
            if next <= MAX:
                dfs(next)

dfs(1)
dfs(2)
dfs(3)
dfs(4)
dfs(5)
dfs(6)
dfs(7)
dfs(8)
dfs(9)

r.sort()
print(r[k-1])

Measured memory_bytes: 7548
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#include <map>
/* All our base are belong to AC */
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<int,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;};
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}

int main() {
  string s; cin>>s;
  string t; cin>>t;
  int n=s.size();
  int an=0;
  for(int i=0;i<n;i++) {
    an+=s[i]!=t[i];
  }
  cout<<an<<endl;
}

Measured memory_bytes: 3920
import java.util.Scanner;

public final class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        int[][] lcs = new int[s1.length()+1][s2.length()+1];
        for(int i=1; i<=s1.length(); i++){
            for(int j=1; j<=s2.length(); j++){
                if(s1.charAt(i-1) == s2.charAt(j-1)){
                    lcs[i][j] = lcs[i-1][j-1]+1;
                }else{
                    lcs[i][j] = Math.max(lcs[i-1][j], lcs[i][j-1]);
                }
            }
        }
        
        int i=s1.length(), j=s2.length();
        StringBuilder s = new StringBuilder(); 
        while(lcs[i][j] != 0){
            if(lcs[i][j] > Math.max(lcs[i-1][j], lcs[i][j-1])){
                s.append(s1.charAt(i-1));
                i = i-1;
                j = j-1;
            }else
            if(lcs[i][j] == Math.max(lcs[i-1][j], lcs[i][j-1])){
                if(lcs[i-1][j] > lcs[i][j-1]){
                    i = i-1;
                }else{
                    j = j-1;
                }
            }
        }
        System.out.println(s.reverse());
        sc.close();
    }
}

Measured memory_bytes: 83020
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   cout << "ABC" << N << endl;
   return 0;
}


Measured memory_bytes: 384
s = gets.chomp.chars
t = gets.chomp.chars
min = 1001
for i in 0..(s.size-t.size)
    count = 0
    for j in 0..(t.size - 1)
        if t[j] != s[i+j]
            count += 1
        end
    end
    if count < min
        min = count
    end
end
puts min

Measured memory_bytes: 14328
def main():
  s = input()

  for op in range(16):
    t = s[0]
    for j in range(3):
      if (op & (1 << j)):
        t = t + "+"
      else:
        t = t + "-"
      t = t + s[j+1]
    #print(op,t,eval(t))
    if eval(t) == 7:
      print(t + "=7")
      exit(0)
      
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 9052
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const vector<pll> dir={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm (ll a,ll b) {return a*b/gcd(a,b);}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}

vector<ll> func,inv;
void init(ll n){
    func.resize(n+1);inv.resize(n+1);
    func[0]=1;
    rep(i,0,n) {func[i+1]=func[i]*(i+1)%MOD;}
    inv[n]=intpow(func[n],MOD-2);
    rrep(i,1,n+1) {inv[i-1]=inv[i]*i%MOD;}
}
ll comb(ll a,ll b) {return func[a]*inv[b]%MOD*inv[a-b]%MOD;}

inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}

int main(){
    ll n,ans=0;
    cin>>n;
    vector<ll> a(n),b(n),c(n-1);
    rep(i,0,n) cin>>a[i];
    rep(i,0,n) cin>>b[i];
    rep(i,0,n-1) cin>>c[i];
    rep(i,0,n-1){
        ans+=b[a[i]-1];
        if(a[i+1]-a[i]==1) ans+=c[a[i]-1];
    }
    ans+=b[a[n-1]-1];
    cout<<ans;
}

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

int main() {
  long H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) return cout << 1 << "\n", 0;
  cout << ((H * W % 2) ? H * W / 2 + 1 : H * W / 2) << "\n";
}

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

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using vi  = vector<int>;

int main(){
    int n;
    cin >>n ;
    vi a(n);
    rep(i,n) cin >> a[i];

    int cnt = 0;
    rep(i,n){
        if(i % 2 == 0 && a[i] % 2 == 1){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = new String[]{sc.next(), sc.next()};
        System.out.println((s[0] + s[0]).contains(s[1]) ? "Yes" : "No");
    }
}

Measured memory_bytes: 26280
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}


signed main() {
	ll n,a,b;
	scanf("%lld %lld %lld", &n, &a, &b);
	vector<ll> p(n);
	REP(i, n) {
		scnaf("%lld", &p[i]);
	}

	sort(ALL(p));

	ll sa = a - b;

	ll l = 0, r = 1000000001;

	while (1) {
		ll mid = (l + r) / 2;

		ll cou = 0;
		REP(i, n) {
			ll cur = p[i] - b * mid;
			if(cur > 0)
				cou += (cur + sa-1)/sa;
		}

		if (cou > mid) {
			l = mid;
		}
		else r = mid;

		if (r - l <= 1) {
			printf("%lld\n", r);
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;

int main(){
    int H,W,N,ans=0;
    cin>>H>>W>>N;
    if (H>W) cout<<(N-1)/H+1<<endl;
    else cout<<(N-1)/W+1<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long long n,m,l,i,j,k,a,b;
    cin>>n >>m>>l;
    
    int aik[n][m];
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            aik[i-1][j-1]=0;
            
        }
        
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            cin>>a;
            aik[i-1][j-1]=a;
            
        }
           
    }
    int bkj[m][l];
    for(i=1;i<=m;i++){
        for(j=1;j<=l;j++){
            bkj[i-1][j-1]=0;
        }
    }
    for(i=1;i<=m;i++){
        for(j=1;j<=l;j++){
            cin>>b;
            bkj[i-1][j-1]=b;
            
        }
    }
    
    
    
    long long int cij[n][l];
    for(i=1;i<=n;i++){
        for(j=1;j<=l;j++){
            cij[i-1][j-1]=0;
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=l;j++){
            for(k=1;k<=m;k++){
                cij[i-1][j-1]+=aik[i-1][k-1]*bkj[k-1][j-1];
            }
            
           
        }
    }
    for(int i = 0; i < n; i++){
	    for(int j = 0; j < l-1; j++){
			cout<<cij[i][j]<<" ";
		}
		cout<<cij[i][l-1]<<endl;
	}
    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int N, L;
	cin >> N >> L;
	vector<string> v(N);
	rep(i, N) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	rep(i, N) {
		cout << v[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=200010;
const int inf=2147483647;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x*f;
}
int n,f[Maxn],g[Maxn];LL sum[Maxn],a[Maxn],tmp[4];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),sum[i]=sum[i-1]+a[i];
	f[2]=1;
	for(int i=3;i<n-1;i++)
	{
		f[i]=f[i-1];
		while(abs(sum[i]-2LL*sum[f[i]+1])<=abs(sum[i]-2LL*sum[f[i]]))++f[i];
	}
//	return 0;
	g[n-1]=n;
	for(int i=n-2;i>2;i--)
	{
		g[i]=g[i+1];
//		printf("%d %d\n",i,g[i]);
		while(abs(sum[n]-2LL*sum[g[i]-2]+sum[i-1])<=abs(sum[n]-2LL*sum[g[i]-1]+sum[i-1]))--g[i];
	}
	LL ans=7e18;
	for(int i=2;i<n;i++)
	{
		tmp[0]=sum[i]-sum[f[i]];
		tmp[1]=sum[f[i]];
		tmp[2]=sum[n]-sum[g[i+1]-1];
		tmp[3]=sum[g[i+1]-1]-sum[i];
		sort(tmp,tmp+4);
		ans=min(ans,tmp[3]-tmp[0]);
//		ans=min(ans,abs(sum[i]-2LL*sum[f[i]])+abs(sum[n]-2LL*sum[g[i+1]-1]+sum[i]));
	}
	printf("%lld",ans);
}

Measured memory_bytes: 4992
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
MOD = 10**9+7

N = iin()
p = fln()

dp = [[0 for _ in range(N+1)] for _ in range(N+1)]

dp[0][0] = 1
for i in range(N):
    for j in range(N):
        dp[i+1][j+1] += dp[i][j]*p[i]
        dp[i+1][j] += dp[i][j]*(1-p[i])
ans = 0.0
for i in range(N//2+1, N+1):
    ans += dp[N][i]
print(ans)


Measured memory_bytes: 278264