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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int h,w,d;
    cin>>h>>w>>d;
    vector<vector<int>> a(h,vector<int>(w));
    map<int,pair<int,int>> m;
    vector<ll> s(100000);
    for(int i=0;i<h;++i)for(int j=0;j<w;++j){
        cin>>a[i][j];
        m[a[i][j]] = {i,j};
    }
    for(int i=1;i<=d;++i){
        int pre = i;
        for(int j=i+d;j<100000;j+=d){
            auto pi = m[pre];
            auto ind = m[j];
            int score = abs(pi.first - ind.first) + abs(pi.second - ind.second);
            s[j] += s[pre]+ score;
            pre = j;
        }
    }
    int q;
    cin>>q;
    for(int i=0;i<q;++i){
        int l,r;
        cin>>l>>r;
        cout << s[r] - s[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 10564
/**
 * @Author:      G_BG
 * @DateTime:    2018-10-06 17:17:26
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
#define MST(a, b) memset(a, b, sizeof(a));
#define CLR(a) MST(a, 0);
#define pb push_back
#define rep(x, y, z) for (int x = y; x < z; ++x)
#define dwn(x, y, z) for (int x = y; x >= z;--x)
#define lowbit(x) (x & (-x))
typedef long long LL;
typedef unsigned long long ULL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn=1e5+10;
int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(0);cin.tie(0);
    int n,m,c;cin >> n >> m >> c;
    cout << ((n+m)>=c?"Yes":"No") << endl;
   // system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long int n,k;
long long int a[200005];
bool check(long long int m)
{
    int sl = 0;
    for (long long int i = 1; i<= n ; i++ )
    {
        sl += (a[i]/m);
        if(a[i]%m == 0)
            sl --;
    }
    if (sl<=k) return true;
    return false;
}
int main()
{
    cin >> n >> k;
   long long int d = 1, c = -1, g, m = -1;
    for (long long int i = 1; i <= n ; i ++ )
    {
        cin >> a[i];
        if (c<a[i]) c=a[i];
    }

    while ( d <= c )
    {
        g = (d+c)/2;
        if (check(g))
        {
            m = g;
            c = g - 1;
        }
        else
            d = g + 1;
    }
    cout << m;
    return 0;
}



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

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    for(int i = 1; i <= s.size() - 2; ++i){
        if((s.size() - i) % 2 != 0){
            continue;
        }
        string t = s.substr(0, s.size() - i);
        string t2 = t.substr(0, t.size() / 2);
        if(t == t2 + t2){
            cout << t.size() << endl;
            break;
        }
    }
    return 0;
}


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

// --------------------------------------------------------------------------------
#define fastio	ios_base::sync_with_stio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------


void solve_main()
{
    long long l;cin>>l;
    cout<<fixed<<setprecision(12)<<(double)(l*l*l)/27;
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("/home/suryakant/input.txt","r",stdin);
 //        freopen("/home/suryakant/output.txt","w",stdout);
 //    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve_main();
    }
    
}

Measured memory_bytes: 3740
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
      
      int result = 0;
      result = a - b*2;
      if (result >= 0) {
      System.out.println(result);
      }
      else {
      System.out.println(0); 
      }
    }
}

Measured memory_bytes: 23764
#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; }

const int N = 3001;
int dp[N][N + N] = {};
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, t;
    cin >> n >> t;
    vector <pii> a(n);
    for (auto &i : a) {
        cin >> i.x >> i.y;
    }
    sort(all(a));
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < N + N; j++) {
            dp[i][j] = -INF;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < N + N; j++) {
            umax(dp[i + 1][j], dp[i][j]);
            if (j + a[i].x < N + N && j < t) {
                umax(dp[i + 1][j + a[i].x], dp[i][j] + a[i].y);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < N + N; i++) {
        umax(ans, dp[n][i]);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 73980
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

int main()
{
    int64_t N, X;
    std::cin >> N >> X;

    std::vector<int64_t> M;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        X -= t;
        M.push_back(t);
    }

    std::sort(std::begin(M), std::end(M));

    int count = N;

    count += (X / M[0]);

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import string
f = sys.stdin

ceasar1 = str.maketrans(string.ascii_lowercase, string.ascii_lowercase[1:] + string.ascii_lowercase[:1])

for sentence in f:
    for i in range(len(string.ascii_lowercase)):
        sentence = sentence.translate(ceasar1)
        if 'the' in sentence or 'this' in sentence or 'that' in sentence:
            print(sentence, end='')
            break

Measured memory_bytes: 6724
fun main(args: Array<String>): Unit {
    val sc = java.util.Scanner(System.`in`)
    val s = sc.nextInt()

    fun f(n : Int) : Int {
        return if (n % 2 == 0) n / 2 else n * 3 + 1
    }

    val list = mutableListOf<Int>()
    var v = s
    var i = 1
    while (true) {
        i++
        list.add(v)
        val m = f(v)
        if (m in list) {
            println(i)
            break
        }
        v = m
    }
}

Measured memory_bytes: 29484
while s=gets.split
  break if s==['0','0']
  h,w=s.map(&:to_i)
  (1..h).each{|i| (1..w).each{|j|
    if i%2==0
      print j%2==0 ? "#":"."
    else
      print j%2==0 ? ".":"#"
    end
    }
    puts
  }
  puts
end

Measured memory_bytes: 6104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n, m, ans=0;
    cin >> n;
    int t[n];
      for(int i=0; i<n; i++){
        cin >> t[i];
        ans += t[i];
      }
    cin >> m;
    int p, x;
      for(int i=0; i<m; i++){
        cin >> p >> x;
        cout << ans-(t[p-1]-x) << endl;
      }

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,c,sum=3,check;
	scanf("%d%d%d",&a,&b,&c);
	if(a==b){
		sum--;
	}
	if(b==c){
		sum--;
	}
	if(c==a){
		sum--;
	}
	check=sum;
	if(check==0){
		sum=1;
	}
	printf("%d",sum);
	return 0;
}	

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

int n;

const int MAX_N = 1e2 + 47;

vector<int> g[MAX_N];

signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  #ifdef _47
    freopen("4.cpp", "r", stdin), freopen("7.cpp", "w", stdout);
  #endif
  cin >> n;
  vector<pair<int, int>> kek;
  for (int i = 0; i <= n; i++)
  {
    for (int j = i + 1; j <= n; j++)
    {
      g[i].push_back(j);
      g[j].push_back(i);
    }
  }
  if (n % 2 == 0)
  {
    for (int i = 1, z = 0; z < n / 2; i++, z++)
    {
      kek.push_back({i, n - i + 1});
      g[i].erase(find(g[i].begin(), g[i].end(), n - i + 1));
      g[n - i + 1].erase(find(g[n - i + 1].begin(), g[n - i + 1].end(), i));
    }
  }
  else
  {
    n--;
    g[n].erase(find(g[n].begin(), g[n].end(), 0));
    g[0].erase(find(g[0].begin(), g[0].end(), n));
    for (int i = 1, z = 0; z < n / 2; i++, z++)
    {
      kek.push_back({i, n - i + 1});
      g[i].erase(find(g[i].begin(), g[i].end(), n - i + 1));
      g[n - i + 1].erase(find(g[n - i + 1].begin(), g[n - i + 1].end(), i));
    }
  }
  set<pair<int, int>> ans;
  for (int i = 1; i <= n; i++)
  {
    for (auto v : g[i])
    {
      if (v != 0)
      {
        ans.insert({min(v, i), max(v, i)});
      }
    }
  }
  cout << ans.size() << '\n';
  for (auto x : ans)
  {
    cout << x.first << ' ' << x.second << '\n';
  }
  return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        char ch[] = str.toCharArray();
        int r = 0;
        int max = 0;
        for(int i=0;i<ch.length;i++){
            if(ch[i]=='R'){
                r++;
            }
            else{
                max = Math.max(max,r);
                r=0;
            }
        }
        max = Math.max(max,r);
        System.out.println(max);
    }
}

Measured memory_bytes: 32416
let
  N = parse(Int, readline())
  A = zeros(Int, N)
  B = zeros(Int, N)
  for i = 1:N
    A[i], B[i] = map(x -> parse(Int, x), readline() |> split)
  end
  sort!(A)
  sort!(B)
  println(B[N÷2 + 1] - A[N÷2 + 1] + (B[N÷2] - A[N÷2]) * (1 - N%2) + 1)
end


Measured memory_bytes: 208124
# coding: utf-8
n,c=map(int,input().split())
lane_r=[]
lane_l=[]
for i in range(n):
    a,b=map(int,input().split())
    lane_r.append((a,b))
    lane_l.append((c-a,b))
lane_l=lane_l[::-1]
acm_lane_r=[0]
acm_lane_l=[0]
for i in range(n):
    acm_lane_r.append(acm_lane_r[-1]+lane_r[i][1])
    acm_lane_l.append(acm_lane_l[-1]+lane_l[i][1])
for i in range(1,n+1):
    acm_lane_r[i]-=lane_r[i-1][0]
    acm_lane_l[i]-=lane_l[i-1][0]
mxl=0
mxr=0
pl=0
pr=0
for i in range(n+1):
    if mxl<acm_lane_l[i]:
        mxl=acm_lane_l[i]
        pl=lane_l[i-1][0]
    acm_lane_l[i]=(mxl,pl)
    if mxr<acm_lane_r[i]:
        mxr=acm_lane_r[i]
        pr=lane_r[i-1][0]
    acm_lane_r[i]=(mxr,pr)
mx=0
lane_r.insert(0,(0,0))
lane_l.insert(0,(0,0))
for i in range(n+1):
    mx=max(acm_lane_r[n-i][0]+acm_lane_l[i][0]-min(acm_lane_r[n-i][1],acm_lane_l[i][1]),mx)
for i in range(n+1):
    mx=max(acm_lane_l[n-i][0]+acm_lane_r[i][0]-min(acm_lane_l[n-i][1],acm_lane_r[i][1]),mx)
print(mx)



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

int main(){
  int count=0;
  int N;
  cin>>N;
  vector<int>P(N);
  for(int i=0;i<N;i++){
    cin>>P[i];
    if((P[i]-1)!=i){
      count++;
    }
  }
  if(count<=2){
  cout<<"YES";
  }
  else{
   cout<<"NO"; 
  }
}


Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll ans[100010] = {};
    ll N = S.size();
    vector<ll> l_pos, r_pos;
    rep(i,0,N){
        if(S[i] == 'L'){
            l_pos.push_back(i);
        }else{
            r_pos.push_back(i);
        }
    }

    rep(i,0,N){
        if(S[i] == 'R'){
            ll idx = lower_bound(l_pos.begin(), l_pos.end(), i) - l_pos.begin();
            ll tt = l_pos[idx];
            if((tt - i) % 2 == 0){
                ans[tt]++;
            }else{
                ans[tt-1]++;
            }


        }else{
            ll idx = lower_bound(r_pos.begin(), r_pos.end(), i) - r_pos.begin();
            ll tt = r_pos[idx-1];
            if((i - tt) % 2 == 0){
                ans[tt]++;
            }else{
                ans[tt+1]++;
            }
        }
    }
    rep(i,0,N){
        cout << ans[i] << " \n"[i==N-1];
    }
    
}


Measured memory_bytes: 2372
#include <stdio.h>

int main(void){
	
	int a;
	int b;
	int c;
	int num;
	
	scanf("%d %d %d",&a,&b,&c);
	num = a;
	a = b;
	b = num;
	
	num = a;
	a = c;
	c = num;
	
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if((a + b) < 24 ){
    cout << a + b << endl;
  }
  if((a + b) >= 24){
    cout << a + b -24 << endl;
  }
}

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

typedef long long ll;
const int N = 1e5;

inline bool cek_bit(ll mask, int x){
	return mask&(1ll<<x);
}

int n;
ll li[N+5];

int depan[65];
int urut = 0;
int matrix[65][N+5];

bool masuk(int bit){
	urut++;
	for(int i=1;i<=n;i++){
		if(cek_bit(li[i],bit)){
			matrix[urut][i] = 1;
		} else {
			matrix[urut][i] = 0;
		}
	}
	matrix[urut][n+1] = 1;
	for(int i=1;i<urut;i++){
		if(matrix[urut][depan[i]] == 1){
			for(int j=1;j<=n+1;j++){
				matrix[urut][j]^=matrix[i][j];
			}
		}
	}
	int awal = -1;
	for(int i=1;i<=n;i++){
		if(matrix[urut][i] == 1){
			awal = i;
			break;
		}
	}
	if(awal == -1 && matrix[urut][n+1] == 0){
		urut--;
		return 1;
	} else if(awal == -1 && matrix[urut][n+1] == 1){
		urut--;
		return 0;
	}
	depan[urut] = awal;
	return 1;
}

int main(){
	scanf("%d",&n);
	ll ans = 0ll;
	for(int i=1;i<=n;i++){
		scanf("%lld",&li[i]);
	}
	for(int i=59;i>=0;i--){
		int cnt = 0;
		for(int j=1;j<=n;j++){
			if(cek_bit(li[j],i)){
				cnt++;
			}
		}
		if(cnt&1){
			ans+=(1ll<<i);
		} else {
			if(masuk(i)){
				ans+=(1ll<<(i+1));
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 25216
N = int(input())
A_upper = list(map(int, input().split()))
A_lower = list(map(int, input().split()))
 
max_A_sum = 0
 
for i in range(N):
    # 1行目のiまでと2行目のiからを加算
    A_sum = sum(A_upper[:i+1]) + sum(A_lower[i:])
    # print(A_sum,(A_upper[:i+1]),(A_lower[i:])
    # 比較
    if A_sum > max_A_sum:
        max_A_sum = A_sum
 
print(max_A_sum)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>

int main() {
  std::string   a, b;
  long			num;
  
  std::cin >> a >> b;
  num = std::stoi( a+b );
  if ( sqrt(num) == (int) sqrt(num) )
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No"  << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m, c, b[21], a;

int main(){
	cin >> n >> m >> c;
	for(ll i = 1; i <= m; i++){cin >> b[i];}
	
	ll ans = 0;
	for(ll j = 1; j <= n; j++){
		ll buf = 0;
		for(ll i = 1; i <= m; i++){
			cin >> a;
			buf += a*b[i];
		}
		if(buf+c > 0){ans++;}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)
#define sp(n) setprecision(n)
#define mp make_pair
#define mt make_tuple
#define pi 3.14159265358979323846264
#define MOD 1000000007

using namespace std;
int primeFactors(ll n)  
{  ll f=0;
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        f++;
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            f++; 
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        f++;
        
 return f;        
}  
  
bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}
 
ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++){
            if (j == 0 || j == i){C[i][j] = 1;}
            else{C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);}}}
    return C[n][k];
 }
 
ll gcd(ll a, ll b){if (b == 0)
        return a;return gcd(b, a % b);}
 
ll expmod(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}
//define temp-functions below
 
 
//some definitions and global variables
vector<ll> primes;
void storePrime(ll n){
    fori(n){
        if(isPrime(i+1)&&(n%(i+1)==0)){primes.push_back(i+1);}
    }
}
 
int main(){ //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);

 
      ll n,r;cin>>n>>r;
      if(n>=10) cout<<r;
      else cout<<r+(100)*(10-n);
      
      
      
      
      
      
      
      
      
      
    

return 0;}

Measured memory_bytes: 256
from sys import stdin


def f(s, p, P, i):
    # 再帰
    # 順にスイッチを見ていく
    if len(s) == i:
        return 1 if P == p else 0
    # 場合の数
    # そのスイッチを使用しなかった場合 + 使用した場合
    return f(s, p, P, i + 1) + f(s, p, P ^ s[i], i + 1)


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    sn = [[int(j) for j in i.split()[1:]] for i in lines[1:-1]]
    pn = (int(i) for i in lines[-1].split())
    # s[スイッチID]
    # 2進数における桁はそのスイッチを使用している電球
    s = [0] * N
    for i in range(M):
        for j in sn[i]:
            s[j - 1] |= (1 << i)
    # p
    # 2進数における桁は電球 ゼロイチをそのまま2進数とする
    p = 0
    for i, j in enumerate(pn):
        p |= (1 << i) if j == 1 else 0
    print(f(s, p, 0, 0))


main()


Measured memory_bytes: 3064
def main():
    N, A, B = map(int, input().split())
    S = input()

    total = A + B
    domestic = 0
    overseas = 0

    for i in S:
        if i == 'a':
            if domestic + overseas < total:
                print('Yes')
                domestic += 1
                continue
        elif i == 'b':
            if domestic + overseas < total and overseas < B:
                print('Yes')
                overseas += 1
                continue

        print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 4016
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define 	pb 				push_back
#define 	MOD 			1000000007
#define 	pp 				pop_back
#define 	MAXN   			1000001
#define 	mp 				make_pair
#define 	endl 			'\n'
#define 	ff 				first
#define 	ss 				second
#define 	mapcl 			map<char,ll>
#define 	mapll 			map<ll,ll>
#define 	pll 			pair<ll,ll>
#define 	cmp 			complex<double>
#define 	pi 				3.141592653589793238462643383279502884197169399375105820974944592307816406286 
#define 	inf 			1000
#define 	vll 			vector<ll>
#define 	all(v) 			v.begin(),v.end()
#define 	fr(i,z,n) 		for(ll i=z;i<n;i++)
#define 	sqrt 			sqrtl
#define 	cbrt 			cbrtl
#define		ll 				long long
#define 	ld 				long double
bool 		coll(pll p1,pll p2,pll p3)		{if((p3.ss-p2.ss)*(p2.ff-p1.ff)==(p2.ss-p1.ss)*(p3.ff-p2.ff))return true;else return false;}
void		print(auto x)					{cout<<x<<endl;}
void 		pv(vector<auto> v)				{for(ll i=0;i<(ll)v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void 		pvsl(vector<auto> v)			{for(ll i=0;i<(ll)v.size();i++)cout<<v[i]<<" ";}
void 		in(vector<auto> &v, ll n)		{v.resize(n);for(ll i=0;i<n;i++)cin>>v[i];}
void 		sortv(vector<auto> &v)			{sort(v.begin(),v.end());}
void 		fast()							{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
ll maxi(ll a, ll b){ 
	if (a > b)
		return a;
	return b;
}
ll mini(ll a, ll b){
	if (a > b)
		return b;
	return a;
}
pair<ll, ll> getdig(ll x){
	ll end = x%10, start;
	while (x > 0){
		start = x%10;
		x /= 10;
	}
	return mp(start, end);
}
int main(){
	ll n, ans = 0;
	cin >> n;
	map<pair<ll, ll>, ll > m;
	for (ll i=1;i<=n;i++){
		pair<ll, ll> tmp = getdig(i);
		m[tmp] += 1;
	}
	for (ll i=1;i<=n;i++){
		pair<ll, ll> tmp = getdig(i);
		ans += m[mp(tmp.second, tmp.first)];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int wholeLcm = 1;
		int[] denominator = new int[n];
		int totalMolecule = 0;
		for(int i=0;i<n;i++){
			denominator[i] = sc.nextInt();
			wholeLcm = lcm(wholeLcm,denominator[i]);
		}
		
		for(int i=0;i<n;i++){
			totalMolecule += wholeLcm/denominator[i];
		}
		
        System.out.println((double)wholeLcm/totalMolecule);
	}
      
	static int lcm (int a, int b) {
		int temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (int)(c/b);
	}
}


Measured memory_bytes: 23764
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int a[n];
    for(int i=n;i>0;i--){cin >> a[i-1];}
    for(int i=0;i<n-1;i++){cout << a[i] << " ";}
    cout << a[n-1] << endl;
    
}


Measured memory_bytes: 3096
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] l = new int[n];
    for (int i = 0; i < n; i++) {
      l[i] = sc.nextInt();
    }
    int sum = 0;
    Arrays.sort(l);
    for (int i = 0; i < n - 2; i++) {
      int a = l[i];
      for (int j = i + 1; j < n - 1; j++) {
        int b = l[j];
        for (int k = j + 1; k < n; k++) {
          int c = l[k];
          if (a != b && a != c && b != c && a + b > c) {
            sum++;
          }
        }
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 36600
#include <iostream>

using namespace std;

int main(){
	int a, b, c;
	char d;
	int cho=0;
	int hi=0;

	while(cin >> a >> d >> b >> d >> c){


		if(a*a + b*b == c*c){
			cho++;
		}
		else if(a == b){
			hi++;
		}
	}
	cout << cho << endl << hi << endl;

}

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

#define int 		long long
#define vi 			vector <int>
#define si 			set <int>
#define pii 		pair<int,int>
#define fr(n) 		for(__typeof(n) i=0;i<n;i++)
#define rep(i,a,b) 	for(__typeof(b) i=a;i<b;i++)
#define repi(i,b,a) for(__typeof(a) i=b;i>=a;i--)
#define tr(a) 		for(auto it=a.begin();it!=a.end();it++)
#define pb 			push_back
#define mp 			make_pair
#define F 			first
#define S 			second
#define FAST 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define time_passed	1.0 * clock() / CLOCKS_PER_SEC

void solve()
{
	int n,m;
	cin>>n>>m;
	int s,c;
	int a[n],flag=0;
	memset(a,-1,sizeof(a));
	fr(m)
	{
		cin>>s>>c;
		s--;
		if(a[s]==-1)
		{
			a[s]=c;
		}
		else if(a[s]!=c)
		{
			flag=1;
		}
	}
	if(a[0]==0 and n>1)
		flag=1;
	if(a[0]==-1 and n>1)
		a[0]=1;
	else if(a[0]==-1 and n==1)
		a[0]=0;
	if(flag)
		cout<<-1;
	else
	{
		for(int i=0;i<n;i++)
		{
			if(a[i]==-1)
				cout<<0;
			else
				cout<<a[i];
		}
	}
}

signed main()
{
	FAST
	int test=1;
	//cin>>test;
	while(test--)
	{
		solve();
	}
	cerr<<endl<<"Time elapsed : "<<time_passed<<endl;
	return 0;
}

Measured memory_bytes: 3780
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin >> s;
  int ans=0;
  if(s.size()>1){
    REP(i,s.size()-1){
      if(s[i]!=s[i+1]) ans++;
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 512
#! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)



def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def solve(H: int, W: int, M: int, _h: "List[int]", _w: "List[int]"):
    H_count = [0] * (H+1)
    W_count = [0] * (W+1)
    G = set()
    seenH = set()
    seenW = set()
    for i in range(M):
        h,w=_h[i],_w[i]
        H_count[h] += 1
        W_count[w] += 1
 
        seenH.add(h)
        seenW.add(w)
        G.add((h,w))
    
    Hs = []
    Ws = []
    for i in range(max(H,W)+1):
        if i < len(H_count):
            count = H_count[i]
            if count > 0:
                Hs.append((count,i))
 
        if i < len(W_count):
            count = W_count[i]
            if count > 0:
                Ws.append((count,i))
 
 
    Hs.sort(reverse=True)
    Ws.sort(reverse=True)
 
    # print(Hs)
    # print(Ws)
 
    h_count,h = Hs[0]
    w_count,w = Ws[0]
 
    original = h_count + w_count
    ans = original
    if (h,w) in G:
        # print("a")
        ans -= 1
 
        i = 1
        sameH = []
        while i < len(Hs) and Hs[i][0] == h_count:
            # print("h")
            h = Hs[i][1]
            i += 1
            sameH.append(h)
        
        i = 1
        sameW = []    
        while i < len(Ws) and Ws[i][0] == w_count:
            w = Ws[i][1]
            i += 1
            sameW.append(w)
           
        max_mass = (len(sameH)+1) * (len(sameW)+1)
 
        # print(max_mass)
        on_bom_count = 0
        for h,w in G:
            count = H_count[h] + W_count[w]
            if count == original:
                on_bom_count += 1
        
        if max_mass - on_bom_count > 0:
            ans += 1
 
                
    print(ans)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    h = [int()] * (M)  # type: "List[int]"
    w = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        h[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(H, W, M, h, w)



if __name__ == "__main__":
    main()


Measured memory_bytes: 202660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t A, B, K;
  cin >> A >> B >> K;
  if (A >= K) {
    cout << A - K << " " << B << endl;
  }
  else if (A + B >= K) {
    cout << 0 << " " << A + B - K << endl;
  }
  else {
    cout << 0 << " " << 0 << endl;
  }
}

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

#define STRING(str) #str
#define ll long long

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

using S = int;
S op(S l, S r) {
	return max(l, r);
};
S e() {
	return 0;
}


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

	int N, K;
	cin >> N >> K;
	segtree<S, op, e> seg(1e6);
	for (int i=0;i<N;i++) {
		int A;
		cin >> A;
		int max_val = seg.prod(max(0, A-K), A+K+1);
		seg.set(A, max_val+1);
	}
	cout << seg.prod(0, 1e6) << endl;
}

Measured memory_bytes: 15304
using System;
using System.Linq;
using System.IO;

public class pg{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        var x = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
        var xave = (int)x.Average();
        var a1=0;
        var a2=0;
        for(var i=0;i<n;i++){
            var t1=Math.Abs(x[i]-xave);
            var t2=Math.Abs(x[i]-xave-1);
            a1+=t1*t1;
            a2+=t2*t2;
        }
        
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Console.WriteLine(Math.Min(a1,a2));
        Console.Out.Flush();
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
#include <ctype.h>

int main(void){
	char ch;
	while(1){
		scanf("%c",&ch);

		if(ch=='\n') break;

		if(!islower(ch)){
			ch = tolower(ch);
		}
		else{
			ch = toupper(ch);
		}
		printf("%c",ch);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
n,m = map(int,input().split())
cnt = [0]*(n+1)
for _ in range(m):
	a,b = map(int,input().split())
	cnt[a] ^= 1
	cnt[b] ^= 1
for i in cnt:
	if i:
		print("NO")
		exit()
print("YES")

Measured memory_bytes: 3956
n = int(input())
b = list(map(int, input().split()))

ans = []
for _ in range(n):
    for i, bi in enumerate(b[::-1]):
        i = len(b) - i
        if i == bi:
            ans.append(b.pop(i-1))
            break
print(*(ans[::-1] if len(ans) == n else[-1]), sep='\n')


Measured memory_bytes: 63564
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        s: chars,
    }
    let a = s.contains(&'A');
    let b = s.contains(&'B');
    if a && b {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int n,k,a=0;
    cin>>n>>k;
    while(n){
    	a++;
    	n/=k;
    }
    cout<<a;	
	return 0;
}


Measured memory_bytes: 256
def merge(a, left, mid, right):
    global cnt
    l = a[left:mid] + [sentinel]
    r = a[mid:right] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
            cnt += mid - left - i


def merge_sort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

n = input()
a = list(map(int, input().split()))
sentinel = 10 ** 9 + 1
cnt = 0
merge_sort(a, 0, len(a))
print(cnt)

Measured memory_bytes: 39492
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,W; cin>>H>>W;
    vector<vector<char>>S(H+2,vector<char>(W+2,0));
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            cin>>S[i][j];
        }
    }
    int dx[8]={0,1,1,1,0,-1,-1,-1};
    int dy[8]={1,1,0,-1,-1,-1,0,1};
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            if(S[i][j]=='#'){
                cout<<'#';
            }
            else{
                int count=0;
                for(int k=0;k<8;k++) {
                    int nx = j + dx[k];
                    int ny = i + dy[k];
                    if(S[ny][nx]=='#') {
                        count++;
                    }
                }
                cout<<count;
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
def is_prime(a):
    for i in range(2,int(math.sqrt(a))+1):
        if a%i==0:
            return False
    return True

n = int(input())
cnt = 0
for i in range(n):
    x = int(input())
    if is_prime(x):
        cnt+=1
print(cnt)


Measured memory_bytes: 5672
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>

#define rep(i, n) for(int i = 0, end = (int)(n); i < end; i++)

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

int main() {
    int n, k;
    cin >> n >> k;
    cout << ((n % k == 0) ? 0 : 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 110
signed main()
{
    //ios_base::sync_with_stdio(false);
    string a;
    cin>>a;
    if(a[2]==a[3]&&a[4]==a[5])cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pii pair<int,int>
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int w,h,x,y,r;
  cin>>w>>h>>x>>y>>r;
  if(x-r>=0 && x+r<=w){
    if(y-r>=0 && y+r<=h) co("Yes");
    else co("No");
  }
  else co("No");
  
  return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,x=0;
    char c;
    cin>>a;
    string s[a];
    for(i=0;i<a;i++)
    {
        cin>>c;
        s[i]=c;
    }
    for(i=0;i<a;i++)
    {
        if(s[i]=="A"&& s[i+1]=="B" && s[i+2]=="C")
        {
            x++;
            i+=2;
        }

    }
    cout<<x<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict

n = int(input())
arr = list(input().split())
q = int(input())
num_counts = defaultdict(lambda: 0)
ans = 0

for i in arr:
  num_counts[i] += 1
  ans += int(i)

for _ in range(q):
  bef, af = list(input().split())
  apper_count = num_counts[bef]
  ans += (int(af) - int(bef)) * apper_count
  num_counts[bef] -= apper_count
  num_counts[af] += apper_count
  print(ans)


Measured memory_bytes: 27984
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x;
    cin>>x;
    ll ans=0;
    ll temp1=x/500;
    x%=500;
    ll temp2=x/5;
    ans=(temp1*1000)+(temp2*5);
    cout<<ans;
    return 0;
}







Measured memory_bytes: 256
// adios amigos!!
#include <bits/stdc++.h>
#include <chrono>
#include <random>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#define rep(i,n) for(ll i = 0; i < n; ++i)
#define ed end()  
#define bg begin()
# define ld long double
#define ll long long
#define ub(v,a) upper_bound(all(v),a)
#define lb(v,a) lower_bound(all(v),a)
#define sz(a) (int)(a.size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tr(v,it) for(auto it=v.begin();it!=v.end();it++)
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.
#define vpresent(v,x) (find(all(v),x)!=v.end()) // vector
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
typedef vector< long long > vll;
typedef vector<pair<ll,ll>> vp;
typedef vector< vll > vvll;
typedef pair< int,int > pi;
const long long max_sz = 1e5 + 1;
const long long mod = 1e9 + 7;
const long long MAXN = 4e18 + 1;
const int N=500023;
#define PI 3.1415926535897932384626
char flip(char k){ if(k=='0') return '1'; return '0'; }
ll sum_digit(ll n){ ll a=0,i; for(i=n;i>0;i=i/10){ a+=(i%10);} return a; }
ll gcd(ll a, ll b){if(b == 0) return a;return gcd(b, a%b);}
bool isPowerOfTwo(int n){if(n==0)return false;return (ceil(log2(n)) == floor(log2(n)));}
//DEBUGGING
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
const int LG = 20;
//__builtin_popcount(n) -> returns number of set bits in n
ll expo(ll a, ll b, ll m); // a^(b) %m
//=======================

//vector<bool> vis;vis.assign(n,false); g.assign(n,{});
//vector<vll> g;
//void ipgraph(ll m){ll  u, v;while(m--){cin>>u>>v; u--, v--;g[u].pb(v);g[v].pb(u);}}
//ll lvl[N], p[N][LG];
//ll lca(ll u,ll v){if(lvl[u]<lvl[v])swap(u,v);ll i,lg; for(lg=0;(1<<lg)<=lvl[u];lg++);lg--;for(i=lg;i>=0;i--){if(lvl[u]-(1<<i)>=lvl[v]){u=p[u][i];}}if(u==v)return v;else{for(i=lg;i>=0;i--){if(p[u][i]!=-1 && p[u][i]!=p[v][i]){u=p[u][i];v=p[v][i];}}}return p[u][0];}

void solve(){
    ll d,tim,s;cin>>d>>tim>>s;
    if(ceil((ld)d/s)>tim)cout<<"No\n";
    else cout<<"Yes\n";
}

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


ll expo(ll a, ll b, ll m) 
{ 
    if (b == 0)return 1; 
    ll p = expo(a, b / 2, m) % m; 
    p = (p * p) % m; 
  
    return (b % 2 == 0) ? p : (a * p) % m; 
} 

Measured memory_bytes: 3592
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

min_limit = min(a, b, c, d, e)
if n % min_limit == 0:
    cnt = n // min_limit
else:
    cnt = n // min_limit + 1
print(5 + cnt - 1)


Measured memory_bytes: 9132
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int aYear = 0;
		int bYear = 0;
		boolean flag = true;

		while(true) {
			aYear = sc.nextInt();
			bYear = sc.nextInt();

			if(aYear == 0 && bYear == 0) {
				break;
			}

			if(!flag) {
				System.out.println();
				flag = true;
			}


			for(int $ = aYear; $ <= bYear; $++) {
				if(($ % 4 == 0) && (($ % 100 != 0) || ($ % 400 == 0))) {
					System.out.println($);
					flag = false;
				}
			}

			if(flag) {
				System.out.println("NA");
				flag = false;
			}
		}

	}

}

Measured memory_bytes: 27360
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+7;
ll f[N];
int main()
{
	int n, W;
	scanf("%d%d", &n, &W);
	for(int i = 1; i <= n; i++)
	{
		int w, v;
		scanf("%d%d", &w, &v);
		for(int j = W; j >= w; j--)
		{
			f[j] = max(f[j], f[j-w]+v);
		}
	}
	printf("%lld\n", f[W]);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

//a,b x
int main(){
	ll N; cin>>N;
	vector<ll> A(N+2);
	vector<ll> B(N+1);
	ll cnt=0;
	rep1(i,N+1) cin>>A[i];
	rep1(i,N) cin>>B[i];
	for(int i=1;i<=N;i++){
		if(B[i]<=A[i]) cnt+=B[i];
		else{
			cnt+=A[i];
			cnt+=min(B[i]-A[i],A[i+1]);
			A[i+1]-=min(B[i]-A[i],A[i+1]);
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 1792
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3 4 6
0 0
0 2
0 3
1 1
2 1
2 3

output:
3
"""

import sys


def generate_adj_table(_edges):
    for edge in _edges:
        vx, vy = map(int, edge)
        init_adj_table[vx].append(vy)

    return init_adj_table


def graph_dfs(current, matching, visited):
    for adj in range(y_num):
        if (not visited[adj]) and (adj in adj_table[current]):
            visited[adj] = True
            if matching[adj] == -1 or graph_dfs(matching[adj], matching, visited):
                matching[adj] = current
                return True
    return False


def mbm():
    matching = [-1] * y_num
    res = 0
    for v in range(x_num):
        visited = [False] * y_num
        if graph_dfs(v, matching, visited):
            res += 1
    # print(matching)
    return res


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    x_num, y_num, e_num = map(int, _input[0].split())
    edges = map(lambda x: x.split(), _input[1:])

    init_adj_table = [[] for _ in range(x_num)]
    adj_table = generate_adj_table(edges)
    print(mbm())

Measured memory_bytes: 8428
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] h = new int[N+1];
    for(int i = 1; i <= N; i++) {
      h[i] = sc.nextInt();
    }
    int[] dp = new int[N+1];
    dp[1] = 0;
    dp[2] = Math.abs(h[2] - h[1]);
    for(int i = 3; i <= N; i++) {
      dp[i] = Math.min(dp[i - 1] + Math.abs(h[i] - h[i - 1]), dp[i - 2] + Math.abs(h[i] - h[i - 2]));
    }
    System.out.println(dp[N]);
  }
}

Measured memory_bytes: 51152
#include<bits/stdc++.h>
using namespace std;
int a[101];
int s=0;
void john(int n)
{
	for(int i=0;i<n;i++)
	{
		if(a[i]==a[i+1])
		{
			s++;
			i++;
		}
	}
}

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	john(n);
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;
int main()
{
    int n,m,x,cnt=0,ans=0,ss=0;
    cin>>n>>m>>x;
    int a[m];
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<m;i++)
    {
        if(a[i]<x)
        {
                cnt++;
        }
        else
        {
                        ans++;
        }
    }
    cout<<min(ans,cnt)<<endl;
    return 0;
}
    

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

struct Node{
  Node (int z) : //constracter
    key(z),
    parent(nullptr),
    right(nullptr),
    left(nullptr)
  {}
  int key;
  Node *parent;
  Node *right, *left;
  //right == nullptr && left == nullptr
};

Node *root;

void insert(Node *z){
  Node *y=nullptr;
  Node *x=root;

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

bool find(Node *f, int x){
  if(f == nullptr) return false;
  if(x == f->key) return true;
  else if(x < f->key) return find(f->left, x);
  else return find(f->right, x);
}

void inorder(Node *node){
  if(node->left != nullptr) inorder(node->left);
  std::cout << " " << node->key;
  if(node->right != nullptr) inorder(node->right);
}

void preorder(Node *node){
  std::cout << " " << node->key;
  if(node->left != nullptr) preorder(node->left);
  if(node->right != nullptr) preorder(node->right);
}

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

  int v, f;
  std::string s;
  for(int i=0; i<n; i++){
    std::cin >> s;
    if(s == "insert"){
      std::cin >> v;
      insert(new Node(v));
    }
    else if(s == "find"){
      std::cin >> f;
      if(find(root, f)) std::cout << "yes" << std::endl;
      else  std::cout << "no" << std::endl;
    }
    else{
      inorder(root);
      std::cout << std::endl;
      preorder(root);
      std::cout << std::endl;
    }
  }
  return 0;
}



Measured memory_bytes: 21872
X ,Y ,A ,B ,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p = p[:X]
q = q[:Y]
p.extend(q)
p.sort()
if X+Y > C:
    for i in range(C) :
        if p[i] < r[i]:
            p[i] = r[i]
        else:
            pass
else:
    for i in range(X+Y) :
        if p[i] < r[i]:
            p[i] = r[i]
        else:
            pass
print(sum(p))

Measured memory_bytes: 105444
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 100010


int main(){
	IOS;
	tihs;
	
	ll a,b;cin>>a>>b;
	ld x = 100.00*(ld)a/8.00,y = 10.000*(ld)b;
	ld ans = max(x,y);
	ll z = (ll)ans;
	ll f=-1;
	rep(i,z-10,z+10){
		ll xx = i*8/100,yy = i/10;
		if(xx==a and yy==b){
			f=i;
			break;
		}
	}
	cout<<f;
	return 0;
}

Measured memory_bytes: 256
//config = {stdin: 'tmp', newline: '\r\n'}; // win
config = {stdin: '/dev/stdin', newline: '\n'}; // linux

line = require('fs').readFileSync(config.stdin, 'ascii')
       .split(config.newline)[0].split(' ').map(Number);
(function (a, b, C) {
  console.log('%d\n%d\n%d',
    0.5 * a * b * Math.sin(C),
    a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(C)),
    b * Math.sin(C)
  );
}) (line[0], line[1], line[2] * 2 * Math.PI / 360);

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

using namespace std;

int main() {

	int n, x, qtd4=0, qtd2=0;

	scanf("%d", &n);

	for (int i=0; i<n; ++i) {
		scanf("%d", &x);

		if (x%4 == 0) {
			++qtd4;
		}
		else if (x%2 == 0) {
			++qtd2;
		}
	}

	if (qtd4 >= n/2)
		puts("Yes");
	else if (qtd4 >= ceil((n-qtd2+1)/2))
		puts("Yes");
	else 
		puts("No");

	return 0;
}

Measured memory_bytes: 256
import Control.Monad (replicateM_)
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
    _ <- getLine
    ts <- V.fromList . fmap read . words <$> getLine :: IO (V.Vector Int)
    m <- readLn :: IO Int
    replicateM_ m $ do
        [p, x] <- fmap read . words <$> getLine :: IO [Int]
        let us = ts V.// [(p - 1, x)]
        print $ V.sum us


Measured memory_bytes: 1020