akhauriyash/Code-Regression huggingface dataset:
/*
  AUTHOR:SOURABH
  CREATED:25:03:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t,n,k,i,l,r,sum,ans;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>k>>n;
        vll a(n);
        fn(i,n)
        cin>>a[i];
        vll v;
        fn(i,n-1)
        v.pb(a[i+1]-a[i]);
        v.pb(k-a[n-1]+a[0]);
        sum=0;
        fn(i,n-1)
        sum+=v[i];
        ans=sum;
        l=0,r=n-1;
        //cout<<sum<<endl;
        fs(i,1,n)
        {
            sum=sum-v[l]+v[r];
            //cout<<sum<<endl;
            l++;
            r++;
            l%=n;
            r%=n;
            ans=min(sum,ans);
        }
        cout<<ans;
    }
    return 0;
}








Measured memory_bytes: 3956
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 300010;

int n, m, d[N];
struct Point {int l, r;} a[N];

bool operator < (Point a, Point b) {
	return a.r - a.l < b.r - b.l;
}

namespace BIT {
#define lowbit(i) (i & -i)
int c[N];
void add(int x, int v) {
	for(int i = x; i <= m; i += lowbit(i)) c[i] += v;
}
int query(int x) {
	int ans = 0;
	for(int i = x; i; i -= lowbit(i)) ans += c[i];
	return ans;
}
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%d%d", &a[i].l, &a[i].r);
	sort(a + 1, a + n + 1);
	int cur = 1;
	for(int i = 1; i <= m; ++i) {
		while(cur <= n && a[cur].r - a[cur].l + 1 <= i) {
			BIT::add(a[cur].l, 1); BIT::add(a[cur].r + 1, -1);
			++cur;
		}
		for(int j = i; j <= m; j += i) d[i] += BIT::query(j);
		d[i] += n - cur + 1;
	}
	for(int i = 1; i <= m; ++i) printf("%d\n", d[i]);
	return 0;
} 

Measured memory_bytes: 4096
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
To compute x^y under modulo mod
int power(int x,unsigned int y){
    if(y==0)return 1;
    int p=power(x,y/2,m)%mod;
    p=(p*p)%mod;
    return(y%2==0)?p:(x*p)%mod;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2; p*p<=n; p++)
        if (prime[p] == true)
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int n;
  	cin>>n;
  	int a[10][10]={0};
  	int tcnt=0;
  	rep(i,1,n+1){
  		int j=i;
    	int b=j%10;
    	while(j%10!=j){
			j=j/10;
		}
    	int c=j;
  		a[b][c]++;
  	}
  	rep(i,1,10)rep(j,1,10)tcnt+=a[i][j]*a[j][i];
  	cout<<tcnt<<endl;
	return 0;

}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 256
A_1 = list(map(int,input().split()))
A_2 = list(map(int,input().split()))
A_3 = list(map(int,input().split()))
N = int(input())
b=[]
for i in range(N):
    b.append(int(input()))
    
for i in b:
    for j in range(3):
        if A_1[j] == i:
            A_1[j] = -1

        if A_2[j] == i:
            A_2[j] = -1
            
        if A_3[j] == i:
            A_3[j] = -1


if A_1[0] == A_2[0] == A_3[0] == -1 or A_1[1] == A_2[1] == A_3[1] == -1 or A_1[2] == A_2[2] == A_3[2] == -1:
    print('Yes')
elif A_1[0] == A_1[1] == A_1[2] == -1 or A_2[0] == A_2[1] == A_2[2] == -1 or A_3[0] == A_3[1] == A_3[2] == -1:
    print('Yes')
elif A_1[0] == A_2[1] == A_3[2] == -1 or A_1[2] == A_2[1] == A_3[0] == -1:
    print('Yes')
else:
    print('No')            


Measured memory_bytes: 9172
import qualified Data.IntMap.Strict as M
import Data.List

main = do
 [n,w] <- map read . words <$> getLine
 wvs <- map (map read . words) . lines <$> getContents
 print (knap n w wvs)

knap n w wvs = maximum $ M.elems $ foldl' dp (M.singleton 0 0) wvs
 where dp im [w',v'] = M.unionWith max im (M.filterWithKey (\k _ -> k<=w) $ M.mapKeys (+w') $ M.map (+v') im)

Measured memory_bytes: 2556
from itertools import accumulate
import bisect
n,m,k = map(int, input().split())
alist= list(map(int, input().split()))
blist = list(map(int, input().split()))


alist = list(accumulate(alist))
blist = list(accumulate(blist))

alist.insert(0,0)
blist.insert(0,0)

ans = 0
j = m
for i in range(0,n+1):
  if alist[i] > k:
    pass
  else:
    while blist[j] > k - alist[i]:
      j -= 1
    ans = max(ans,i+j)

print(ans)

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

int main(){
    string x; cin >> x;
    deque<char> ans;
    for (auto i = 0; i < (int)x.size(); i++) {
        if(i < (int)x.size() - 1) {
            if(x[i] == 'S' and x[i + 1] == 'T') { i++; continue; }
        }
        if(not ans.empty()) {
            if(ans.back() == 'S' and x[i] == 'T') { ans.pop_back(); continue; }
        }
        ans.push_back(x[i]);
    }
    cout << ans.size() << endl;
    return 0;
}

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

#include <vector>
int main()
{
    int k, n;
    cin >> k >> n;
    int a, a_prev;
    vector<int> diff;
    a = 0;
    a_prev = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        diff.push_back(a - a_prev);
        a_prev = a;
        // cout << diff[i] << endl;
    }
    // for (int i = 0; i < n; ++i) 
    //     cout << diff[i] << " ";
    // cout << endl;
    diff[0] = diff[0] + k - a;
    // cout << diff[0] << endl;
    // cout << diff[diff.size() - 1] << endl;

    int max_diff = -1;
    int max_index = -1;
    for (int i = 0; i < diff.size(); ++i) {
        // cout << diff[i] << endl;
        if (diff[i] > max_diff) {
            max_diff = diff[i];
            max_index = i;
            // cout << max_diff << endl;
        }
    }

    cout << k - max_diff << endl;

    return 0;
}



Measured memory_bytes: 1400
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] a=new int[n];
    for (int i=0;i<n;++i) {
      a[i]=sc.nextInt();
    }

    int count=1,ans=0;
    for (int i=0;i<n;++i) {
      if (a[i]==count) {
        ++count;
      }
      else{
        ans++;
      }
    }
    if (count!=1) {
      System.out.println(ans);
    }
    else if (ans==0) {
      System.out.println("0");
    }
    else{
      System.out.println("-1");
    }
  }
}


Measured memory_bytes: 85116
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define sz(x) (int)x.size()
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define F first
#define S second
#define watch(x) cerr << "\n" << (#x) << " = " << (x) << "\n"
using namespace std;
int d, t, s;

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> d >> t >> s;
	float x = (float)d / s;
	if(x <= t)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 3636
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif
void solve() {
    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n - 1; i++) {
        int x, y;
        cin >> x >> y;
        if(x > y)
            swap(x, y);
        ans -= (1LL * x) * (n + 1 - y);
        ans += (i * 1LL * (i + 1)) / 2;
    }
    ans += (n * (n + 1)) / 2;
    cout << ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 3688
package main

import (
    "fmt"
    "os"
    "bufio"
    "strings"
    "strconv"
)

func main() {
    var fp *os.File = os.Stdin
    reader := bufio.NewReaderSize(fp, 1024)

    line := readLine(reader)
    arr := strings.Split(line, " ")
    K, _ := strconv.Atoi(arr[0])
    S, _ := strconv.Atoi(arr[1])

    var cnt = 0

    for x := 0; x <= K; x++ {
        for y := 0; y <= K; y++ {
            //for z := 0; z <= K; z++ {
                z := S - x - y

                if z >= 0 && z <= K && x + y + z == S {
                    cnt++
                }
            //}
        }
    }

    fmt.Println(cnt)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 105;
const int MOD = 1000000007;

int anspush[maxn * maxn][maxn];
int n, k;

inline void upd(int &a, ll b)
{
    a = (a + b) % MOD;
}

int main()
{
    scanf("%d%d", &n, &k);
    
    ll sum = 0;
    ll cnt = 1;
    anspush[0][n + 1] = 1;
    for (int i = n; i > 0; i--)
    {
        sum = ((ll)sum * (k + 1) + (k + 1) * k / 2 * cnt) % MOD;
        cnt = ((ll)cnt * (k + 1)) % MOD;
        for (int npushs = 0; npushs <= (n - i) * k; npushs++) if (anspush[npushs][i + 1] != 0)
        {
            for (int t = 0; t <= k; t++)
            {
                if (t > i)
                {
                    upd(anspush[npushs][i], anspush[npushs][i + 1]);
                } else
                {
                    upd(anspush[npushs + (t + npushs) / i][i], anspush[npushs][i + 1]);
                }
            }
        }
    }
//     cout << sum << endl;
    for (int i = 0; i <= n * k; i++)
    {
//         cout << i << ' ' << anspush[i][1] << endl;
        sum = (sum - (ll)anspush[i][1] * i) % MOD;
    }
    sum = (sum + MOD) % MOD;
    cout << sum << endl;
    
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) ans -= a.at(i);
    else if (i == n - 1) ans += a.at(i);
    else ans += abs(a.at(i));
  }
  
  cout << ans << '\n';
  
  int keep = a.front(), keep2 = a.back();
  for (int i = 1; i < n - 1; i++) {
    if (a.at(i) >= 0) {
      cout << keep << " " << a.at(i) << '\n';
      keep -= a.at(i);
    }
    else {
      cout << keep2 << " " << a.at(i) << '\n';
      keep2 -= a.at(i);
    }
  }
  cout << keep2 << " " << keep << '\n';
}

Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <set>

int main() {
    std::set<int> s;

    for (int i = 0; i < 3; i++) {
        int n;

        std::cin >> n;
        s.insert(n);
    }

    std::cout << s.size() << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    ll N; cin >>N;
    multiset<ll> POS, NEG, ZER;
    stringstream ss;
    if(N==2){
        ll x, y;
        cin >> x >> y;
        if(x<y) swap(x, y);
        cout << x-y << endl;
        cout << x << " " << y <<endl;
        return 0;
    }
    REP(i, N){
        ll x; cin>>x;
        if(x>0) POS.insert(x);
        else if(x<0) NEG.insert(x);
        else ZER.insert(x);
    }
    if(NEG.size()==0){
        if(ZER.size()){
            ll h = *POS.begin();
            NEG.insert(-h);
            POS.erase(POS.begin());
            ZER.erase(ZER.begin());
            ss << 0 << " " << h << "\n";
        }
        else{
            ll l = *POS.begin();
            ll h = *--POS.end();
            NEG.insert(l-h);
            POS.erase(POS.begin());
            POS.erase(--POS.end()); 
            ss << l << " " << h << "\n";
        }
    }
    else if(POS.size()==0){
        if(ZER.size()){
            ll h = *NEG.begin();
            POS.insert(-h);
            NEG.erase(NEG.begin());
            ZER.erase(ZER.begin());
            ss << 0 << " " << h << "\n";
        }
        else{
            ll l = *NEG.begin();
            ll h = *--NEG.end();
            POS.insert(h-l);
            NEG.erase(NEG.begin());
            NEG.erase(--NEG.end()); 
            ss << h << " " << l << "\n";
        }
    }
    ll pos = *POS.begin(); POS.erase(POS.begin());
    ll neg = *NEG.begin(); NEG.erase(NEG.begin());
    for(auto &x: NEG){
        ss << pos << " " << x << "\n";
        pos -= x;
        
    }
    for(auto &x: POS){
        ss << neg << " " << x << "\n";
        neg -= x;
    }
    for(auto &x: ZER){
        ss << pos << " " << x << "\n";
    }
    ss << pos << " " << neg << "\n";
    cout << pos-neg << endl;
    cout << ss.str();
    cout <<flush;
    return 0;
}

Measured memory_bytes: 10116
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif

template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }

void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
    for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
        if ( i!=x.cbegin() ) putchar(' ');
        _W(*i);
    }
}

void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
    _W(head);
    putchar(sizeof...(tail)?' ':'\n');
    W(tail...);
}

#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
    freopen(name ".in","r",stdin); \
    freopen(name ".out","w",stdout); \
} while (0)
#endif

// }}}

int main() {
    char s[20];
    R(s);
    REP(i,12) {
        if ( i==4 ) putchar(' ');
        putchar(s[i]);
    }
    W("");
    return 0;
}


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

int main()
{
    int arr[5];
    cin>>arr[0]>>arr[1]>>arr[2]>>arr[3]>>arr[4];
    bool flag=true;
    int k;
    cin>>k;
    for(int i=0;i<5;i++)
    {
        for(int j=i+1;j<5;j++)
        {
            int p=arr[j]-arr[i];
            if(p>k)flag=false;
        }
    }
    if(flag)cout<<"Yay!"<<endl;
    else cout<<":("<<endl;
}


Measured memory_bytes: 256
void main() {
    int[] tmp = readln.split.to!(int[]);
    int a = tmp[0], b = tmp[1], c = tmp[2];
    writeln(a <= c && c <= b ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

int main() {
  int a, b, c, d;
  int t1 = 0, t2 = 0;
  cin >> a >> b >> c >> d;
  while(0 < a){
   t1++;
   a -= d;
  }
  while(0 < c){
   t2++;
   c -= b;
  }
  if(t2 <= t1){
   cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0

for i in range(n):
	if b[i] > a[i]:
		c += a[i]
		b[i] -= a[i]
		if b[i] >= a[i+1]:
			c += a[i+1]
			a[i+1] = 0
		else:
			c += b[i]
			a[i+1] -= b[i]
	else:
		c += b[i]
print (c)

Measured memory_bytes: 19156
A, B, C, X, Y = list(map(int, input().split()))

# A 1枚、B 1枚を2C円で買うと捉え直す。
# ピザは、最大でも10**5枚（A, Bそれぞれに対して）
# A, Bのセットを、1~10**セットまで動かして一番安い組を考える

cheapest = float("inf")

for i in range(max(X, Y) + 1):

    price = 2 * C * i + A * max(0, X - i) + B * max(0, Y - i)

    cheapest = min(cheapest, price)

print(cheapest)


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

using namespace std;

int main() {
	string S;
	cin >> S;
	int ans = 0, count = 0;
	for (int i=0; i<S.size(); i++) {
		if (S[i] == 'R') {
			count++;
			if (ans < count) ans = count;
		} else {
			count = 0;
		}
	}
	cout << ans;
}

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

using namespace std;

int main()
{
    long long h,n;
    cin>>h>>n;
    vector<long long> v(n);
    long long sum = 0;
    for(int i = 0;i<n;i++)
    {
        cin>>v[i];
        sum += v[i];
    }

    if(sum >= h)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    

    return 0;
}

Measured memory_bytes: 4048
import sys
input = sys.stdin.readline

N, K, S = (int(i) for i in input().split())  
#a = [int(i) for i in input().split()] 
#e = [[int(i) for i in input().split()] for i in range(n)] 

seq = []
i = 0
for i in range(K):
    seq.append(S)

for j in range(0, N-K):
    if 2*S > 10**8:
        seq.append(1)
    else:
        seq.append(2*S)

print(" ".join(map(str, seq)))         


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    string s,t;
    cin >>s>>t;
    map<string,int>mp;
    int a,b;cin >>a>>b;
    mp[s]+=a;
    mp[t]+=b;
    string u;cin >>u;
    mp[u]--;
    cout <<mp[s]<<" "<<mp[t]<<endl;
    return 0;
}



Measured memory_bytes: 384
from itertools import combinations

def main(H, W, K, HW):
    ans = 0

    # もとのHWに含まれる黒の数を数える．
    n_all = sum(HW, []).count('#')

    # 組み合わせ生成
    comb_h = []
    comb_w = []
    for h in range(H):
        comb_h.extend(combinations([i for i in range(H)], h))
    for w in range(W):
        comb_w.extend(combinations([i for i in range(W)], w))

    # h行目にある黒の数を数える．
    for c_h in comb_h:
        n_h = 0
        for h in c_h:
            n_h += HW[h].count('#')

        # w行目にある黒の数を数える．
        for c_w in comb_w:
            n_w = 0
            n_hw = 0
            for w in c_w:
                for h in range(H):
                    if HW[h][w] == '#':
                        n_w += 1
                        if h in c_h:
                            n_hw += 1
            # print(c_h, c_w, n_h, n_w, n_hw)
            n_black = n_all - n_h - n_w + n_hw
            if n_black == K:
                ans += 1
    print(ans)

if __name__ == '__main__':
    H, W, K = list(map(int, input().split()))
    HW = []
    for h in range(H):
        HW.append(list(input()))
    main(H, W, K, HW)

Measured memory_bytes: 9264
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Map<Integer, Integer> map = new HashMap<>();
    int N = sc.nextInt();
    for (int i= 0; i < N; i++) {
      int D = sc.nextInt();
      map.put(D, map.getOrDefault(D, 0)+1);
    }
    
    boolean ans = true;
    int M = sc.nextInt();
    for (int i = 0; i < M; i++) {
      int T = sc.nextInt();
      if (map.getOrDefault(T, 0) == 0) {
        ans = false;
        break;
      }
      map.put(T, map.get(T)-1);
    }
    
    System.out.println(ans ? "YES" : "NO");
  }
}

Measured memory_bytes: 134036
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

bool isPrime(long long n){
    for(long long i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return n != 1;
}

signed main(){
    ll x;
    cin >> x;
    for(ll i = x; ; i++){
        if(isPrime(i)){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string base;
    cin >> base;
    REP(i,base.size()){
        if(base[i] != '?'){
            continue;
        }else if(base.size() == 1){
            base[i] = 'D';
        }else if(i == 0){
            if(base[i+1] == 'P'){
                base[i] = 'D';
            }else{
                base[i] = 'P';
            }
        }else if(i == base.size()-1){
            base[i] = 'D';
        }else{
            if(base[i-1] == 'P'){
                base[i] = 'D';
            }else if(base[i+1] == 'P'){
                base[i] = 'D';
            }else{
                base[i] = 'P';
            }
        }
    }
    cout << base << "\n";
}

Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main(){
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
}

Measured memory_bytes: 256
#!/bin/bash
retuInt=0
max(){
	local re;
	if (( $1>$2 )); then
		re=$1
	else
		re=$2
	fi
	retuInt=$re
	}

min(){
	local re;
	if (( $1<$2 )); then
		re=$1
	else
		re=$2
	fi
	retuInt=$re
	}
abs(){
	local re;
	if (( $1>=0 )); then
		re=$1
	else
		re=$((-$1))
	fi
	retuInt=$re
}
read -p "" n
read -p "" line
ma=0
mi=1000000001
for i in $line
do
	max $ma $i
	ma=$retuInt
	min $mi $i
	mi=$retuInt
	
done
abs $((ma-mi))
echo $retuInt

Measured memory_bytes: 376
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N,K;
	cin>>N>>K;
	long long int A[N],sum=0;
	int i;
	for(i=0;i<N;i++)
	{
		cin>>A[i];
	}
	sort(A,A+N);
	for(i=0;i<K;i++)
	sum=sum+A[i];
	
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
struct UnionFind{
    vector<int> par;
    int cnt;
    UnionFind(int N):par(N,-1),cnt(N){}
    void init(int N){par.assign(N,-1);}
    int root(int x){
        if(par[x]<0)return x;
        return par[x]=root(par[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool merge(int x,int y){
        x=root(x),y=root(y);
        if(x==y)return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        cnt--;
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};
struct Edge{
    double a,b,cost;
    bool operator<(const Edge &o){
        return cost<o.cost;
    }
};
vector<double> x,y,z,r;
double dist(int i,int j){
    double X=(x[i]-x[j])*(x[i]-x[j]),
            Y=(y[i]-y[j])*(y[i]-y[j]),
            Z=(z[i]-z[j])*(z[i]-z[j]);
    return sqrt(X+Y+Z);
}
bool touch(int i,int j){
    return dist(i,j)<=r[i]+r[j];
}
void solve(int n){
    x.assign(n,(double)0),y.assign(n,0),z.assign(n,0),r.assign(n,0);
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>z[i]>>r[i];
    //scanf("%llf %llf %llf %llf",&x[i],&y[i],&z[i],&r[i]);
    UnionFind Tree(n);
    vector<Edge> a;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(touch(i,j))Tree.merge(i,j);
            else{
                Edge ne;
                ne.a=i,ne.b=j,ne.cost=dist(i,j)-r[i]-r[j];
                a.push_back(ne);
            }
        }
    }
    sort(a.begin(),a.end());
    double ans=0;
    for(int i=0;i<a.size();i++){
        if(Tree.issame(a[i].a,a[i].b))continue;
        ans+=a[i].cost;
        Tree.merge(a[i].a,a[i].b);
    }
    cout<<fixed<<setprecision(3)<<ans<<endl;
    //printf("%.3llf\n",ans);
}
int main(){
    while(true){
        int n;scanf("%d",&n);
        if(n)solve(n);
        else break;
    }
    return 0;
}


Measured memory_bytes: 3436
#include <iostream>
using namespace std;
typedef long long ll;
ll n, a[3], b;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> b;
        if (b % 4 == 0) a[0]++;
        else if (b % 4 == 2) a[1]++;
        else a[2]++;
    }
    if (a[1]) {
        cout << (a[2] > a[0] ? "No" : "Yes") << endl;
    } else {
        cout << (a[2] > a[0] + 1 ? "No" : "Yes") << endl;
    }
}


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

void mSort(int *array,int N){
  	int temp = 0;
  
  	for(int i = 0; i < N - 1; i++){
      for(int j = i + 1; j < N; j++){ 
        if(array[i] < array[j]){
          temp = array[i];
          array[i] = array[j];
          array[j] = temp;
        }
      }
    }  
}


int main(void){
 
  int N;
  int Alice = 0;
  int Bob = 0;
  
  cin >> N;
  
  int array[N];
  
  for(int i = 0; i < N; i++){
    cin >> array[i];
  }
  
  mSort(array,N);
  
  for(int i = 0; i < N; i++){
  	if(i % 2 == 0){
      Alice += array[i];
    }
    else{
      Bob += array[i];
    }
  }
  
  cout << Alice - Bob << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> par; // 親ノード
  vector<int> rank; // ランク

  UnionFind(int n) { //初期化
    int N=n+1;
    par.resize(N); rank.resize(N);
    rep(i,N) {par[i] = i, rank[i] = 0;}
  }

  int root(int x) { //ノードの根を返す
    if (par[x] == x) return x; //親が自分なら自分を返す
    else {
      int r = root(par[x]); //根まで遡る
      return par[x] = r;
    }
  }

  bool issame(int x, int y) { //同じ根ならtrue,ちがうならfalse
    return root(x) == root(y);
  }

  bool merge(int x, int y) { //ノードを接続する
    x = root(x); y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x; //ランクの小さい方に接続
    return true;
  }
};

void Main(){

  int N,K,L;

  cin>>N>>K>>L;

  UnionFind tree1(N);
  UnionFind tree2(N);

  rep(i,K){
    int p,q;
    cin>>p>>q;
    tree1.merge(p-1,q-1);
  }

  rep(i,L){
    int r,s;
    cin>>r>>s;
    tree2.merge(r-1,s-1);
  }

  vector<pair<ll, int>> p;
  rep(i,N){
    int r1,r2;
    r1=tree1.root(i);
    r2=tree2.root(i);
    //p.emplace_back(r1*1000000+r2,i);
  }

  map<pair<ll, ll>, ll> mp;
  rep(i,N){
    mp[{tree1.root(i),tree2.root(i)}]++;
  }
  rep(i,N){
    cout << mp[{tree1.root(i),tree2.root(i)}] <<" ";
  }
/*
  int ct=1;

  SORT(p);

  ll pp=p[0].first;

  int ans[N];

  reps(i,1,N+1){
    if(p[i].first==pp and i!=N) ct++;
    else{
      rep(j,ct){
        ans[p[i-j-1].second]=ct;
      }
      if(i!=N) pp=p[i].first;
      ct=1;
    }
  }

  rep(i,N){
    cout << ans[i] <<" ";
  }
*/
}

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


Measured memory_bytes: 15104
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000009;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

int main(){
	long long a,b,c,d,e;
	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e);
	b=min(b,a*2);
	c=min(c,b*2);
	d=min(d,c*2);
	long long ret=0;
	ret+=e/2*d;
	e%=2;
	ret+=c*e;
	printf("%lld\n",ret);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  cout << (N - 1 + K - 2) / (K - 1) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#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++)
#define FORALL(i, m) for( auto i = m.begin(); i != m.end() ; ++i )
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define TM_T template <class T>
#define MOD 1000000007
using namespace std;
typedef long long ll;
TM_T T inp(){T it;cin >> it;return it;}

int N, MA, MB;
vector<ll> la,lb,lc;
vector<vector<ll>> dp;

int input(){
  cin >> N >> MA >> MB;
  REP(i,N) {
    la.push_back( inp<ll>() );
    lb.push_back( inp<ll>() );
    lc.push_back( inp<ll>() );
  }
}

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

int main()
{
  input();
  
  REP(i,500) {
    dp.push_back( vector<ll>() );
    REP(j,500) dp[i].push_back( INF );
  }
  dp[0][0] = 0;
  
  REP(i,N){
    ll ai=la[i],bi=lb[i],ci=lc[i];
    REPR(a,450){
      REPR(b,450){
        dp[a+ai][b+bi] = min(dp[a+ai][b+bi],dp[a][b]+ci);
      }
    }
  }
  
  ll s = INF;
  REP(a,450){
    REP(b,450){
      if (a==0 & b==0) continue;
      ll r = gcd(a,b);
      if ( a==MA*r & b==MB*r){
        //cout << a << "," << b << endl;
        s = min(s,dp[a][b]);
      }
    }
  }
  cout << ((s==INF)?-1:s) << endl;

  
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D);
    
    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n, m;
	cin >> n >> m;
	vector<int> v(m);

	int ans = 0;
	rep(_, n) {
		int k;
		cin >> k;
		rep(i, k) {
			int a;
			cin >> a;
			a--;
			v[a]++;
			if (v[a] == n)
				ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define boost ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0)
#define vi vector<int>
#define P push_back
#define F first
#define S second
#define debug(x) cout<<x<<" "
#define pi vector<pair<int,int> >
#define FOR(i,x,n) for(int i=x;i<n;i++)
using namespace std;

int main(){
    boost;
  int a,p;
  cin>>a>>p;
  cout<<(a*3+p)/2;

return 0;
}


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

int main(void) {
    int x1, x2, y1, y2;
    int x3, x4, y3, y4;
    int a, b;

    cin >> x1 >> y1 >> x2 >> y2;

    a = x2 - x1;
    b = y2 - y1;

    x3 = x2 - b;
    y3 = y2 + a;

    x4 = x1 - b;
    y4 = y1 + a;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
const int coin[] = {500,100,50,10,5,1};
int main() {
	int n;
	while (scanf("%d",&n)&&n!=0) {
		int res=0,turi=1000-n,m=0;
		while (turi!=0) {
			if (turi<coin[m]) {
				m++;
			} else {
				turi -= coin[m];
				res++;
			}
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 0
a = []
y = []

for i in range(5):
    b = int(input())
    a.append(b)
    
import itertools

c =itertools.combinations(a,2)

for v in c:
    d = list(v)
    x = abs(d[0]-d[1])
    y.append(x)
    
n = int(input())

m = 0

for l in range(len(y)):
    if y[l] > n:
        print(":(")
        break
    else:
        m += 1
        if m == (len(y)):
            print('Yay!')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
	int n;
	cin >> n;
	int ans = 0;
	LOOP(i,n){
		int a;
		cin >> a;
		while(a%2==0){
			a/=2;
			ans++;
		}
	}
	cout << ans << endl;; 
}


Measured memory_bytes: 384
a,b,q=map(int,input().split())
import bisect
inf=10**18
s=[int(input()) for _ in range(a)]
t=[int(input()) for _ in range(b)]
x=[int(input()) for _ in range(q)]
s=[-inf]+s+[inf]
t=[-inf]+t+[inf]
for q in x:
    c,d=bisect.bisect_left(s,q),bisect.bisect_left(t,q)
    ans=float("inf")
    for i in [c,c-1]:
        for j in [d,d-1]:
            ans=min(ans,abs(s[i]-t[j])+abs(q-s[i]),abs(s[i]-t[j])+abs(q-t[j]))
    print(ans)
    

Measured memory_bytes: 86872
#include<iostream>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	int max = -10000;
	int a[3] = { A + B,A - B,A * B };
	for (int i = 0; i < 3; i++) {
		if (a[i] > max)
			max = a[i];
	}
	cout << max;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int n, T;

int Binary_Search(int a[],int key) {
    int left = 0;
    int right = n;
    while (left < right) {
        int mid = (left + right) / 2;
        if (a[mid] == key) {
            return 1;
        } else if (key < a[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return 0;
}

int main() {
    scanf("%d",&n);
    int a[n+1];
    for (int i = 0; i < n; ++i) {
        scanf("%d",&a[i]);
    }
    scanf("%d",&T);
    int b;
    int ans=0;
    for (int i = 0; i < T; ++i) {
        scanf("%d",&b);
        if (Binary_Search(a,b)) ans++;
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 2104
n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [0] * k + p
s = []
a = 0
for i in range(k, n+k):
    a += p[i];
    a -= p[i-k]
    s.append(a)
index = s.index(max(s))
result = 0
for i in p[index+1:index+k+1]:
    result += (i + 1) / 2
print(result)

Measured memory_bytes: 24548
#include <bits/stdc++.h>
#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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
int a,b,x;
cin>>a>>b>>x;
if(a==x){ cout<<"YES"<<endl;}
else if(a<x&&(x-a)<=b) { cout<<"YES"<<endl;}
else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
 
auto& in = std::cin;
auto& out = std::cout;
 
int32_t N;
int32_t A[110001];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);
 
	in >> N;
	for (size_t i = 0; i < N; i++)
	{
		int a;
		in >> a; A[a]++;
	}
 
	int32_t max = 0;
	for (int32_t  i = 1; i < 100010; i++)
	{
		max = std::max(max, A[i - 1] + A[i] + A[i + 1]);
	}
	out << max << endl;
 exit(0);
	return 0;
}
#endif

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

int main() {
  int n;
  cin >> n;
  int cnt = 1;
  bool inc=true, dic=true;
  int m;
  cin >> m;
  rep(i,n-1) {
    int k;
    cin >> k;
    if(!inc&&k>m) {
      inc = true;
      dic = true;
      cnt++;
    }
    else if(!dic&&k<m) {
      inc = true;
      dic = true;
      cnt++;
    }
    else if(k>m) dic = false;
    else if(k<m) inc = false;
    m=k;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("O999")
#define long long ll
const int INF=0x3f3f3f3f;
int maxn=50000005;
using namespace std;

int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int a[n+1], ans=0;
	for(int i=1; i<n; i++) cin >> a[i];
	ans+=a[1],a[n]=a[n-1];
	for(int i=2; i<=n; i++)
		ans+=min(a[i-1],a[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return (a / gcd(a, b)) * b; }


struct UnionFind {
	std::vector<int> _parent;
	std::vector<int> _size;
	UnionFind(int size) : _parent(size, -1), _size(size, 1) { }
	void unite(int a, int b) {
		int ra = root(a), rb = root(b); if (ra == rb) { return; }
		if (_size[ra] >= _size[rb]) { _parent[rb] = ra, _size[ra] += _size[rb]; } else { _parent[ra] = rb, _size[rb] += _size[ra]; }
	}
	int root(int a) {
		int p = _parent[a];
		if (p < 0) { return a; }
		while (_parent[p] >= 0) { p = _parent[p]; }
		return _parent[a] = p;
	}
	int size(int a) { return _size[root(a)]; }
};


void solve(long long N, long long M, std::vector<long long> &A, std::vector<long long> &B) {
	UnionFind uf(N);
	for (LL i = 0; i < M; ++i) {
		uf.unite(A[i], B[i]);
	}
	LL ans = 0;
	for (LL i = 0; i < N; ++i) {
		ans = max(ans, (LL)uf.size(uf.root(i)));
	}
	cout << ans << endl;
}

int main() {
    long long N;
	scanf("%lld", &N);
	long long M;
	scanf("%lld", &M);
	std::vector<long long> A(M);
	std::vector<long long> B(M);
	for (int i = 0; i < M; i++) {
		scanf("%lld", &A[i]); A[i]--;
		scanf("%lld", &B[i]); B[i]--;
	}
	solve(N, M, A, B);
	return 0;
}


Measured memory_bytes: 8032
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

static const int MAX = 1e5;
static const int INF = 1e5;
int n, m, X[MAX], maxx, minx, L[MAX], ans;

int main() {
    scanf("%d %d", &n, &m);
    maxx = (-INF);
    minx = INF;

    for ( int i = 0; i < m; i++ ) {
        scanf("%d", &X[i]);
        maxx = max(maxx, X[i]);
        minx = min(minx, X[i]);
        
    }
    
    sort(X, X+m);

    for ( int i = 0; i < m-1; i++ ) {
        L[i] = X[i+1] - X[i] - 1;
    }

    sort(L, L+m-1, greater<int>());
    ans = maxx - minx - n + 1;

    for ( int i = 0; i < n-1; i++ ) {
        ans -= L[i];
    }
    
    ans = max(ans, 0);
    printf("%d", ans);
    return 0;
}



Measured memory_bytes: 1024
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <assert.h>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>                                    
#include <deque>                                    
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <random>
#include <ctime>
#include <unordered_map>
#include <set>
#include <unordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;

 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

ll x, k, d;

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> x >> k >> d;
   x = abs (x);
   ll need = x / d;
   if (need > k) cout << x - k * d;
   else {
      x -= need * d;
      k -= need;
      if (k % 2 == 0) cout << x;
      else cout << abs (x - d);
   }
}               
 
signed main () {                                       
  // #ifdef QWERTY
   //   freopen("input", "r", stdin);
   //#endif
  // freopen (".in", "r", stdin);    
  // freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                   

Measured memory_bytes: 3660
N = int(input())
A, B = [0]*N, [0]*N
for i in range(N):
  A[i], B[i] = map(int, input().split())

button = 0
for i in range(N)[::-1]:
  q, mod = divmod(A[i], B[i])
  if mod != 0:
    button += (q + 1) * B[i] - A[i]
  if i - 1 >= 0:
    A[i - 1] += button

print(button)

Measured memory_bytes: 14836