akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
from  bisect import bisect_right
inf = float("inf")
A = sorted(list(map(int, input().split())))
BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: -x[1])
cnt = 0
L, R = 0, N
ans = 0
for b, c in BC:
    idx = bisect_right(A, c, lo=L, hi=R)
    idx -= L
    if idx == 0:
        ans += sum(A[L:R])
        break
    elif idx < b:
        ans += sum(A[L+idx:R]) + idx*c
        break
    elif idx >= b:
        ans += sum(A[L+idx:R]) + b*c
        tmp = L
        L += b
        R = tmp + idx     

    cnt += 1
    if cnt == M:
        ans += sum(A[L:R])

print(ans)




Measured memory_bytes: 82584
//#define NDEBUG

#include <bits/stdc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define B back()
#define FR front()
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define modadd(a, b) (((a % MOD) + (b % MOD)) % MOD)
#define modtimes(a, b) (((a % MOD) * (b % MOD)) % MOD)
#define iceil(a) ((int)ceil(a))
#define ifloor(a) ((int)floor(a))

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

int main(){
    StarBurstStream

    int n;
    cin >> n;

    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    vector<int> dp(n);
    dp[1] = abs(h[0] - h[1]);
    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << dp[n - 1] << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int a,b,i,j;
    int d=0,f,g,h;
    scanf("%d",&a);
    int x[a];
    char c[12];
    for(i=0;i<a;i++){
        scanf("%s %d",c,&b);
        if(c[0]=='i'){
            x[i]=b;
        }
        else if(c[6]=='F'){
            i-=2;a-=2;
        }
        else if(c[6]=='L'){
            i--;a--;d++;
        }
        else{
            i--;a--;
            f=0;
            for(j=i;j>=0;j--){
                if(f>0)break;
                if(b==x[j]){
                    g=i-j;
                    h=0;
                    f++;
                    while(g!=h++)x[j+h-1]=x[j+1+h-1];
                i--;a--;
                }
            }
        }
    }
    for(i=0;i<a-d;i++){
        if(i==a-d-1)printf("%d\n",x[a-1-i]);
        else printf("%d ",x[a-1-i]);
    }
    return 0;
}

Measured memory_bytes: 5568
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
data = [0] + data
ans = [0] * (N+1)
for i in range(N,0,-1):
    if data[i] == 1 and sum(ans[::i]) % 2 == 0: 
        ans[i] = 1
    elif data[i] == 0 and sum(ans[::i]) % 2 != 0:
        ans[i] = 1
print(sum(ans))
for ind,k in enumerate(ans):
  if k != 0:
    print(ind,end=" ")

Measured memory_bytes: 8756
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      String s[] = new String[n];
     int flag1 = 0;
     int flag2 = 0;
      
      for(int i =0;i<n;i++){
        s[i]  = sc.next();
      if(i>0){
        if(s[i-1].charAt(s[i-1].length()-1)!=s[i].charAt(0)){
          flag1=1;
        }}
      }
		Arrays.sort(s);
      
      for(int i =1;i<n;i++){
        if(s[i-1].equals(s[i])){flag2=1;}
      }
      if(flag1==0&&flag2==0){System.out.print("Yes");}
      else{System.out.print("No");}
      
    }
}

Measured memory_bytes: 21844
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll n;
    ll m;
    ll ans=0;
    cin >> n >> m;
    vector<vector<ll> > bait_list(100010);
    multiset<ll> reward_list;
    REP(i, n){
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        bait_list[tmp1].push_back(tmp2);
    }

    REP(i, m+1){
        REP(j, bait_list[i].size()){
            //cout << i << " " << j << " " << bait_list[i][j] << endl;
            reward_list.insert(bait_list[i][j]);
        }
        if(! reward_list.empty()){
            ans += *(--reward_list.end());
            reward_list.erase(--reward_list.end() ) ;
        }
    }

    cout << ans << endl;
    return 0;
}

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

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

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

    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    std::vector<int> l(n, 0), r(n + 1, 0);

    for (int i = 1; i < n; i++) {
        l[i] = gcd(l[i - 1], a[i - 1]);
    }

    for (int i = n; i > 0; i--) {
        r[i - 1] = gcd(r[i], a[i - 1]);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = std::max(ans, gcd(l[i], r[i + 1]));
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

int main() {
	int N; cin >> N;
	while (N--) {
		int score = 0;
		int out = 0;
		int run = 0;
		while (out <= 2) {
			string st; cin >> st;
			if (st == "OUT")out++;
			else if (st == "HIT") {
				run++;
				if (run == 4) {
					run = 3;
					score++;
				}
			}
			else {
				score += 1 + run;
				run = 0;
			}
		}
		cout << score << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 int N;
  cin >>N;
  vector<int> vec(N);
  rep(i,N) {
cin >>vec.at(i);
  }
  sort(all(vec));
  int sum=0;
if(N%2==0) {
 rep(i,N/2) {
     
    sum +=vec.at(2*i+1)-vec.at(2*i);
 }
  cout<< sum<< endl;
}
  
    else {
    repl(i,1,N/2+1) {
       
      sum +=vec.at(2*i)-vec.at(2*i-1);
    }
    cout<< sum+vec.at(0)<< endl;
}
  
  
}


Measured memory_bytes: 256
using System;

namespace AlgoStudy
{
  class Program
  {    
    static void Main(string[] args)
    {
      string[] ary = Console.ReadLine().Split(' ');
      int w = int.Parse(ary[0]);
      int h = int.Parse(ary[1]);
      int x = int.Parse(ary[2]);
      int y = int.Parse(ary[3]);
      int r = int.Parse(ary[4]);

      if (r <= x && x <= w - r && r <= y && y <= h - r) Console.WriteLine("Yes");
      else Console.WriteLine("No");

    }
  }
}

Measured memory_bytes: 8972
#include <cstdio>
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
	ll i,n, k;
	scanf("%lld", &n);
	scanf("%lld", &k);

	ll p = n % k;
	ll pp = -1 * (p - k);
	if(p > pp)
		printf("%lld", pp);
	else 
		printf("%lld", p);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    int a[n], b[n];
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }
    ll ans = 0;
    int ma[n], mb[n];
    for (int i = 0; i < 30; i++) {
        int T = 1 << i;
        rep(i, n) {
            ma[i] = a[i] % (2 * T);
        }
        rep(i, n) {
            mb[i] = b[i] % (2 * T);
        }
        sort(mb, mb + n);
        ll sum = 0;
        rep(i, n) {
            sum += lower_bound(mb, mb + n, 2 * T - ma[i]) -
                   lower_bound(mb, mb + n, T - ma[i]);
            sum += lower_bound(mb, mb + n, 4 * T - ma[i]) -
                   lower_bound(mb, mb + n, 3 * T - ma[i]);
        }
        if (sum % 2 == 1) {
            ans += T;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6680
import sys
input = sys.stdin.readline
 
N, A, B = [int(x) for x in input().split()]
X = [int(x) for x in input().split()]

ans = 0

for i in range(N - 1):
    if (X[i + 1] - X[i]) * A > B:
        ans += B
    else:
        ans += (X[i + 1] - X[i]) * A

print(ans)

Measured memory_bytes: 58864
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<bitset>
#include<vector>
#include<queue>
#include<ext/pb_ds/priority_queue.hpp>
#include<set>
#include<map>
#include<math.h>
#include<set>
#define maxn 10000005
#define lson (now<<1)
#define rson ((now<<1)|1)
typedef long long ll;
using namespace std;
int n,m,k;
int f[maxn];
int main()
{
	for(int i=1;i<=1e7;i++)
	{
		for(int j=i;j<=1e7;j+=i)
			f[j]++;
	}
	scanf("%d",&n);
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=1ll*i*f[i];
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 42824
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int N;cin>>N;
	int t1=0,t2,x1=0,x2,y1=0,y2;
	bool pro=true;
	for(int i=0;i<N;i++){
		cin>>t2>>x2>>y2;
		if(((t2-t1)-llabs(x2-x1)-llabs(y2-y1))%2!=0){
			pro=false;
			break;
		}
		else if((t2-t1)-llabs(x2-x1)-llabs(y2-y1)<0){
			pro=false;
			break;
		}
		t1=t2;
		x1=x2;
		y1=y2;
	}
	cout<<(pro ? "Yes" : "No")<<endl;
	return 0;
}

Measured memory_bytes: 256
from math import log2,ceil
N,K = map(int,input().split())

r = [0.5]
for i in range(50):
    r.append(r[-1] / 2)

ans = 0
for n in range(1,N+1):
    if n > K-1:
        ans += 1
        continue
    c = ceil(log2(K/n))
    ans += r[c-1]
print(ans/N)

Measured memory_bytes: 3188
#include <stdio.h>

int main(void){

  char num[1000];
  int a, ii;
  int i = 0;
  long long m = 0;

  for(ii = 0; ii < 1000; ii++){
    num[ii] = '0';
  }
  
  for(ii = 0; ii > -1; ii++){
    scanf("%s", num);
    a = num[0] - 48;
    if(a == 0) return 0;
    while(i < 1000){
      if(num[i] == 0) num[i] = '0'; 
      a = num[i] - 48;
      m += num[i] - 48;
      num[i] = '0';
      i++;
    }
    printf("%lld\n", m);
    m = 0;
    i = 0;
  }
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
const double pi=acos(-1.0);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int main(void){
    long int n;
    cin>>n;
    string str[100200];
    rep(i,n){cin>>str[i];}
    long int a,b,c,d;
    a=0;b=0;c=0;d=0;
    for(int i=0;i<n;++i){
        if(str[i]=="AC")a++;
        if(str[i]=="WA")b++;
        if(str[i]=="TLE")c++;
        if(str[i]=="RE")d++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;

}



Measured memory_bytes: 6756
#include<stdio.h>

int main() {
	int i;
	int a, b;
	char op;
	int cnt = 0;
	int x[10000];

	for (i = 0; i < 10000 && !cnt; i++) {
		scanf("%d %c %d", &a, &op, &b);

		switch (op) {
		case '+':
			x[i] = a + b;
			break;
		case '-':
			x[i] = a - b;
			break;
		case '*':
			x[i] = a * b;
			break;
		case '/':
			x[i] = a / b;
			break;
		case '?':
			if (i==0)return 0;
			cnt = i;
			break;
		}
	}

	for (i = 0; i < 10000 && i < cnt; i++) {
		printf("%d\n", x[i]);
	}
	return 0;

}

Measured memory_bytes: 2688
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
    string S;
    cin >> S;
    char prev;

    int count=0;
    for(int i = 0; i < S.size(); i++){
        if ( i == 0){
            prev = S[i];
            continue;
        }
        if(prev == S[i]){
            if (S[i] == '0'){
                prev = '1';
            }else{
                prev = '0';
            }
            count++;
        }else{
            prev = S[i];
        }
    }


    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

struct node {
    int num;
    int parent;
    int depth;
    vector<node*> children;
    
    node() : num(-1), parent(-1), depth(-1), children() {}
    
    string type() const {
        if(parent==-1) return "root";
        if(children.empty()) return "leaf";
        return "internal node";
    }
    
    int calc_depth(vector<node>& node_list) {
        if(depth>=0) return depth;
        if(parent==-1) return depth = 0;
        return depth = node_list[parent].calc_depth(node_list) + 1;
    }
};

ostream& operator<<(ostream& os, node& e) {
    os << "node " << e.num << ": parent = " << e.parent << ", depth = " << e.depth << ", " << e.type() << ", [";
    for(int i=0; i<e.children.size(); i++) {
        os << (i ? ", " : "") << e.children[i]->num;
    }
    os << "]";
    return os;
}

int main() {
    int n;
    cin >> n;
    vector<int> ids(n);
    vector<vector<int>> children_num(n);
    for(int i=0; i<n; i++) {
        int k, c;
        cin >> ids[i] >> k;
        for(int j=0; j<k; j++) {
            cin >> c;
            children_num[i].push_back(c);
        }
    }
    vector<node> tree(n);
    for(int i=0; i<n; i++) {
        tree[ids[i]].num = ids[i];
        for(int c : children_num[i]) {
            tree[ids[i]].children.push_back(&tree[c]);
            tree[c].parent = ids[i];
        }
    }
    for(auto&& e : tree) e.calc_depth(tree);
    for(auto&& e : tree) cout << e << endl;
    
}


Measured memory_bytes: 11564
import sys
input = sys.stdin.readline
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(N)]
AB.sort(reverse=1,key=lambda x:x[1])
CD.sort()
ans = 0
for c,d in CD:
    for a,b in AB:
        if a<c and b<d:
            ans+=1
            AB.remove([a,b])
            break
print(ans)

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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

const int MAXN = 1000;
const int MAXS = 10000;
ll dp[MAXN + 5][2 * MAXS + 5];

auto maxx(auto& a, auto b){a = max(a, b);}

void reorder(auto& vec, const auto& mapping) {
  auto vec2 = vec;
  auto n = sz(vec);
  rep(i, 0, n)
    vec[i] = vec2[mapping[i]];
}

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

  int n;
  cin >> n;
  vi w(n), s(n), v(n);
  rep(i, 0, n) {
    cin >> w[i] >> s[i] >> v[i];
  }
  vi ind(n);
  iota(all(ind), 0);
  sort(all(ind), [&](int i, int j) {return s[i] + w[i] < s[j] + w[j];});


  reorder(v, ind);
  reorder(w, ind);
  reorder(s, ind);

  
  rep(i, 0, MAXN + 1) rep(j, 0, 2 * MAXS + 1)
    dp[i][j] = -1;
  dp[0][0] = 0;
  rep(i, 0, n) {
    for (int weight = MAXS; weight >= 0; weight--) {
      if (dp[i][weight] == -1) continue;
      maxx(dp[i + 1][weight], dp[i][weight]);
      if (weight <= s[i]) {
	maxx(dp[i + 1][weight + w[i]], dp[i][weight] + v[i]);
      }
    }
  }
  auto res = 0LL;
  rep(i, 0, n + 1)
    maxx(res, *max_element(all(dp[i])));
  cout << res << '\n';
}


Measured memory_bytes: 156672
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  string s, t;
  ll ans = 0;
  cin >> s >> t;
  rep(i, SZ(s)){
    ans += (s[i] != t[i]);
  }
  print(ans);
}


Measured memory_bytes: 3888
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	int ans=unique(a,a+n)-&a[0];
	cout<<ans-(ans%2==0?1:0);
	return 0;
}

Measured memory_bytes: 640
from collections import deque
S = deque(list(input().strip()))
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S.appendleft(C)
      else:
        S.append(C)
    else:
      if int(F) == 1:
        S.append(C)
      else:
        S.appendleft(C)

if flag:
  print(''.join(S))
else:
  print(''.join(list(reversed(S))))
    

Measured memory_bytes: 8420
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;
ll a[101], n;
ll dp[100001];
ll recur(ll stones){
	ll ans = 1, flag = 0;			
	if(dp[stones] != -1)return dp[stones];	
	for(ll i=0;i<n;i++){		
		if(stones - a[i] >= 0){
			flag = 1;
			ans &= recur(stones - a[i]);		
		}	
	}
	if(flag){
		dp[stones] = !ans;
	}else{
		dp[stones] = 0;
	}
	return dp[stones];
}

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,t,q,temp,sum=0,count=0,f=1;
    cin>>n>>k;	
    for(i=0;i<=k;i++){
    	dp[i] = -1;
    }
    for(i=0;i<n;i++){
    	cin>>a[i];
    }
    x = recur(k);
    if(x == 1)cout<<"First";
    else cout<<"Second";
}    
    


Measured memory_bytes: 4224
n = int(input())
s = []
for i in range(n):
    s.append(input())
# [d1, d2, d3, ..., dN]
m = []
a = []
r = []
c = []
h = []
for i in s:
    if i[0] == "M":
        m.append(i)
    elif i[0] == "A":
        a.append(i)
    elif i[0] == "R":
        r.append(i)
    elif i[0] == "C":
        c.append(i)
    elif i[0] == "H":
        h.append(i)

ml = len(m)
al = len(a)
rl = len(r)
cl = len(c)
hl = len(h)

count1 = ml*al*rl + ml*al*cl + ml*al*hl + ml*rl*cl + ml*rl*hl + ml*cl*hl + al*rl*cl + al*rl*hl + al*cl*hl + rl*cl*hl
print(count1)

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

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

  if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0)
    cout << 0 << endl;
  else
    cout << min({A * B, B * C, C * A}) << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int main() {
	ll N,an=0;
	cin >> N;
	vector<ll> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
		an += vec.at(i);
	}
	an *= 2;
	sort(vec.begin(), vec.end());
	if (N % 2 == 0) {
		rep(i, N / 2) {
			an -= 4 * vec.at(i);
		}
		an += (vec.at(N / 2 - 1) - vec.at(N / 2));
	}
	else if(abs(vec.at(N/2-1)-vec.at(N/2))< abs(vec.at(N / 2 + 1) - vec.at(N / 2))) {
		rep(i, N / 2+1) {
			an -= 4 * vec.at(i);
		}
		an += (vec.at(N / 2 - 1) + vec.at(N / 2));

	}
	else {
		rep(i, N / 2 ) {
			an -= 4 * vec.at(i);
		}
		an-= (vec.at(N / 2 + 1) + vec.at(N / 2));
	}



	cout << an << endl;
}


Measured memory_bytes: 1024
import numpy as np

N, W = map(int, input().split())
dp = np.ones(int(1e5+1)) * np.inf
dp[0] = 0
total = 0
for i in range(N):
    w, v = map(int, input().split())
    dp[v:total+v+1] = np.minimum(dp[v:total+v+1], dp[:total+1] + w)
    total += v

print(int(np.where(dp<=W)[0][-1]))

Measured memory_bytes: 29632
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int N = sc.nextInt();
        int A[] = new int[N+1];
        int max = 0;
        for(int i=0;i<N;i++)
        {
            A[i] = sc.nextInt();
        }
        A[N] = K;
        int sum = 0;
        for(int j=0;j<N-1;j++)
        {
            int sa = A[j]-A[j+1];
            if(sa<0)
            {
                sa = sa * (-1);
            }
            if(max<sa)
            {
                max = sa;
            }
            sum = sum + sa;
        }
        int last = A[N]-A[N-1]+A[0];
        if(max<last)
        {
            max = last;
        }
        sum = sum + last;
        System.out.println(sum - max);
        
    }
}

Measured memory_bytes: 85616
package main

import "fmt"

func main() {
        var n, y int
        fmt.Scan(&n, &y)
        yy := y / 1000
        r := search(n, yy)
        fmt.Printf("%d %d %d\n", r.yukichi, r.higuchi, r.natsume)
}

type combi struct{ yukichi, higuchi, natsume int }

func search(n, yy int) combi {
        for i := 0; i <= yy/10; i++ {
                for j := 0; j <= (yy-10*i)/5; j++ {
                        if r := n - i - j; r == yy-10*i-5*j {
                                return combi{i, j, r}
                        }
                }
        }
        return combi{-1, -1, -1}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

const ll MOD = 1e9 + 7;

ll modpow(ll a, ll b, ll m) {
  if (b == 0) return 1;
  ll ret;
  if (b % 2 == 0) {
    ll t = modpow(a, b / 2, m) % m;
    ret = t * t % m;
  } else {
    ll t = modpow(a, (b - 1) / 2, m) % m;
    ret = a * t % m * t % m;
  }
  ret %= m;
  return ret;
}

ll inv(ll a) { return modpow(a, MOD - 2, MOD); }

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

ll lcm(ll a, ll b) { return a % MOD * inv(gcd(a, b)) % MOD * b % MOD; }

map<ll, ll> prime_decomposition(ll n) {
  map<ll, ll> mp;
  for (ll p = 2; p * p <= n; p++) {
    if (n % p != 0) continue;
    ll cnt = 0;
    while (n % p == 0) {
      cnt++;
      n /= p;
    }
    mp[p] = cnt;
  }
  if (n != 1) mp[n] = 1;
  return mp;
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll m = 1e6;
  vector<ll> cnt(1e6 + 1, 0);
  REP(i, n) {
    cin >> a[i];
    map<ll, ll> mp = prime_decomposition(a[i]);
    FOREACH(x, mp) { chmax(cnt[x.first], x.second); }
  }
  ll l = 1;
  REP(i, m + 1) {
    if (cnt[i] == 0) continue;
    (l *= modpow(i, cnt[i], MOD)) %= MOD;
  }
  ll ans = 0;
  REP(i, n) { (ans += l * inv(a[i]) % MOD) %= MOD; }
  cout << ans << endl;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)((x).size())
#define mp make_pair

using namespace std;

typedef unsigned long long ull;
typedef pair<int,int> ii;

template<class U,class T>ostream& operator<<(ostream& out, pair<U,T> & P){
    return out << "[" << P.first << ", " << P.second << "]";
}
template<class T>ostream& operator<<(ostream& out, vector<T> & V){
    if(!V.empty())out << "[";
    for(int i = 0; i < sz(V); i++)out << V[i] << (i+1==sz(V)?"]":", ");
    return out;
}

vector<int> V;

int main(){
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    V.resize(N);
    for(auto &i : V)cin >> i;
    int sm = N+1, br = 0;
    for(auto i:V){
        if(i < sm)br++, sm = i;
    }
    cout << br << endl;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		List<Integer> train = new ArrayList<>();

		while(stdIn.hasNext()){
			int vehicle = stdIn.nextInt();

			switch(vehicle){
				case 0:
                    System.out.println(train.get(train.size() - 1));
					train.remove(train.size() - 1);
					break;

				default:
					train.add(vehicle);
					break;
					
			}

		}

		stdIn.close();
	}
}


Measured memory_bytes: 26244
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<lint> ans;

	auto dfs = [&](auto &&f, lint now) -> void {

		if (now > 3234566667) return;

		ans.emplace_back(now);
		

		if (now % 10 != 9)f(f, now * 10 + now % 10 + 1);
		f(f, now * 10 + now % 10);
		if (now % 10 != 0)f(f, now * 10 + now % 10 - 1);


	};

	for (lint i = 1; i <= 9; i++) {
		dfs(dfs, i);
	}

	sort(ans.begin(), ans.end());
	cout << ans[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 1400
using System;
public class Class1
{
    public static void Main()
    {
        string dataSet =Console.ReadLine();
        string[] data=dataSet.Split();
        int n=int.Parse(data[0]);//row
        int m=int.Parse(data[1]);//column       
        int[] columnSum=new int[m];
        int sum=0;
         
        for (int i =0; i < n; i++)
        {
            string matrixSet =Console.ReadLine();
            string[] matrix=matrixSet.Split();
            int a=0;
            int rowSum=0;
            for(int j =0;j<m;j++)
            {
                a=int.Parse(matrix[j]);
                rowSum+=a;
                columnSum[j]+=a;
            }   
            Console.WriteLine(matrixSet+" "+rowSum);
            sum+=rowSum;            
        }
     
        for(int k=0;k<m;k++)
        {               
                Console.Write(columnSum[k]+" ");                
        }
        Console.Write(sum+"\r\n");      
    }       
}

Measured memory_bytes: 9280
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

cnt = 0
r,g,b,n = inm()
for i in range(n//r+2):
  for j in range((n-i*r)//g+2):
      rest = n-i*r-j*g
      if rest >= 0 and rest%b == 0:
          cnt += 1
print(cnt)


Measured memory_bytes: 3316
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll DIV = 998244353;

map<pair<ll,ll>,ll> Box;
void AddBox(pair<ll,ll> pr) {
   if (Box.count(pr)) Box[pr]++;
   else Box[pr] = 1;
   return;
}

int main(void) {
   ll H,W,N;
   cin>>H>>W>>N;
   ll a,b;

   rep(i,0,N) {
      cin>>a>>b;
      rep(i,-1,2) rep(j,-1,2) {
         if (a-1+i <1 || a-1+i >=H-1) continue;
         if (b-1+j <1 || b-1+j >=W-1) continue;
         AddBox(make_pair(a-1+i,b-1+j));
      }
   }
   ll Num[10] = {};
   for (auto el:Box) {
      // cout<<el.first.first<<" "<<el.first.second<<" "<<el.second<<endl;
      Num[el.second]++;
   }
   Num[0] = (H-2)*(W-2);
   rep(i,1,10) Num[0] -= Num[i];
   rep(i,0,10) cout<<Num[i]<<endl;







   return 0;
}



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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
inline ll ii(){ ll x; cin >> x; return x; }
inline string is(){ string x; cin >> x; return x; }
inline ld id(){ ld x; cin >> x; return x; }
inline void oi(ll x){ cout << x; }
inline void od(ld x){ cout << fixed << setprecision(10) << x; }
inline void os(string x){ cout << x; }
inline void oe(){ cout << endl; }
inline void oie(ll x){ oi(x); oe(); }
inline void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll N=ii();
    ll K=ii();
    queue<ll> A;
    REP(i,0,K){
        A.push(ii());
    }
    REP(i,K,N){
        ll a=ii();
        if(A.front()>=a){
            ose("No");
        }else{
            ose("Yes");
        }
        A.pop();
        A.push(a);
    }
    return 0;
}


Measured memory_bytes: 5240
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

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

    if (S > "2019/04/30") {
        printf("TBD\n");
    } else {
        printf("Heisei\n");
    }

    return 0;
}


Measured memory_bytes: 256
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
//using
using namespace std;
//define
#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
//グローバル変数宣言
int a=0,b=0,c=0;

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


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    char a; cin >> a;
    if(isupper(a)) cout << 'A' << endl;
    else cout << 'a' << endl;
}

Measured memory_bytes: 3620
N = int(input())
a = list(map(int, input().split()))

num = 0
num2 = 0
num4 = 0

for i in a:
    if i % 4 == 0:
        num4 += 1
    elif i % 2 == 0:
        num2 += 1
    else:
        num += 1
num2 %= 2
num += num2
if num4 + 1 >= num:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n;cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
        cin>>a[i];
    int g=a[0];
    for (int i=1;i<n;i++)
        g=__gcd(g,a[i]);
    cout<<g<<endl;
    return 0;
}

Measured memory_bytes: 640
h, w = map(int,input().split())
arr = ['.' * (w + 2)]
flg = True
for _ in range(h):
    tmp = '.' + input() + '.'
    arr.append(tmp)
    tmp = ''
arr += ['.' * (w + 2)]

for i in range(1,h):
    for j in range(1,w):
        base = arr[i][j]
        up = arr[i-1][j]
        down = arr[i + 1][j]
        right = arr[i][j + 1]
        left = arr[i][j - 1]
        if base == '#' and up == down == right == left == '.':
            flg = False
            print('No')
            break
    if not flg:
        break
if flg:
    print('Yes')

Measured memory_bytes: 3064
N = gets.chomp.to_i
a = Array.new(N)
str = gets.split
for i in 0...N do
    a[i] = str[i].to_i
end

b = Array.new(N)
c = Array.new(N)
b[0] = 0
for x in 1...N do
    b[x] = a[x-1] - b[x-1]
end
c[0] = a[N-1] - b[N-1]
for x in 1...N do
    c[x] = a[x-1] - c[x-1]
end
for x in 0...N-1 do
    print (b[x]+c[x])
    print " "
end
puts (b[N-1]+c[N-1])

Measured memory_bytes: 13836
N = int(input())
S = []
for i in range(N):
    S.append(input())

isMARCH = [0]*5
for name in S:
    if name[0] == "M":
        isMARCH[0] += 1
    elif name[0] == "A":
        isMARCH[1] += 1
    elif name[0] == "R":
        isMARCH[2] += 1
    elif name[0] == "C":
        isMARCH[3] += 1
    elif name[0] == "H":
        isMARCH[4] += 1
        
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += isMARCH[i]*isMARCH[j]*isMARCH[k]
            
print(ans)

Measured memory_bytes: 9776
#include<stdio.h>
int main()
{
    long long int r,s,t,u,x,y,z,a,b,c,d,i;
    scanf("%lld%lld%lld%lld", &a,&b,&c,&d);
    r=a*c;
    s=a*d;
    t=b*c;
    u=b*d;
    if(r>=s)
    x=r;
    else
        x=s;
    if(t>=u)
        y=t;
    else
        y=u;
    if(x>=y)
        printf("%lld\n",x);
    else
        printf("%lld\n",y);
    return 0;

}


Measured memory_bytes: 1736
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define repe(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repi(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int main() {
	int n;
	cin >> n;

	vector<ll> t(n);
	rep(i, n)cin >> t[i];
	int m;
	cin >> m;
	vector<pair<int, ll>>p(m);
	rep(i, m)cin >> p[i].first >> p[i].second;
	ll sum = 0;
	rep(i, n) {
		sum += t[i];
	}
	rep(i, m) {
		cout << sum - t[p[i].first - 1] + p[i].second << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
const   int MaxN=1e5+5;
int n,W;
typedef pair<int,int> ii;
ii a[MaxN];
typedef long long ll;
ll f[105][MaxN],res;

void Xuli()
{
    for(int i=0;i<=n;i++)
        for(int j=1;j<=1000*n;j++) f[i][j]=1e15;
    f[0][0]=0;
    for(int i=1;i<=n;i++) f[i][a[i].Y]=a[i].X;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=1000*n;j++)
        {
            f[i][j]=min(f[i][j],f[i-1][j]);
            if (j-a[i].Y>=0 && f[i-1][j-a[i].Y]+a[i].X<=W)
                f[i][j]=min(f[i][j],f[i-1][j-a[i].Y]+a[i].X);
        }
    for(int i=1;i<=1000*n;i++)
        if (f[n][i]!=1e15 && f[n][i]!=0) res=max(res,(ll)i);
    printf("%lld",res);
}

int main()
{
   
    scanf("%d%d",&n,&W);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i].X,&a[i].Y);
    Xuli();
}


Measured memory_bytes: 80256
import math

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sum_a = sum(a)
sum_b = sum(b)
num_b = 0
num_a = 0
for i in range(n):
    if a[i] > b[i]:
        num_b += a[i] - b[i]
    else:
        num_a += math.ceil((b[i]-a[i])/2)

if sum_b-sum_a >= num_b and sum_b-sum_a >= num_a:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4596
#include <iostream>
    using namespace std;
     
    int main() {
    	// your code goes here
    	int n; cin >> n;
    	if(n % 2 == 0)
    	{
    		cout << n / 2;
    	}
    	else if(n % 2 == 1)
    	{
    		cout << (n / 2) + 1;
    	}
    	return 0;
    }

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

int main(){

    int N, M; cin >> N >> M;
    int Q; cin >> Q;

    vector<string> maze(N);

    int G[2005][2005];
    memset(G,0,sizeof(G));
    // E 横向きの辺の個数, F 縦向きの辺の個数
    int E[2005][2005];
    memset(E,0,sizeof(E));
    int F[2005][2005];
    memset(F,0,sizeof(F));

    REP(i,N) cin >> maze[i];
    REP(i,N) REP(j,M) if(maze[i][j]=='1') G[i+1][j+1]++;
    // G 累積和
    REP(i,N) REP(j,M+1) G[i+1][j] += G[i][j];
    REP(i,N+1) REP(j,M) G[i][j+1] += G[i][j];

    REP(i,N) REP(j,M-1) if(maze[i][j+1]=='1' && maze[i][j] == '1') E[i+1][j+1]++;
    REP(i,N-1) REP(j,M) if(maze[i+1][j]=='1' && maze[i][j] == '1') F[i+1][j+1]++;
    // E 累積和
    REP(i,N) REP(j,M) E[i+1][j] += E[i][j];
    REP(i,N+1) REP(j,M-1) E[i][j+1] += E[i][j];
    // F 累積和
    REP(i,N) REP(j,M) F[i][j+1] += F[i][j];
    REP(i,N-1) REP(j,M+1) F[i+1][j] += F[i][j];

    while(Q--) {
        int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d);
        int U = G[c][d] + G[a-1][b-1] - G[c][b-1] - G[a-1][d];
        int V = E[c][d-1] + E[a-1][b-1] - E[c][b-1] - E[a-1][d-1];
        int W = F[c-1][d] + F[a-1][b-1] - F[c-1][b-1] - F[a-1][d];
        // cout << U << " " << V << " " << W << endl;  
        int ans = U - V - W;
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 52992
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

#A,B,K = [int(x) for x in input().split()]
S = input()

cnt_1 = 0
cnt_0 = 0

for s in S:
    if s == "0":
        cnt_0 += 1
    else:
        cnt_1 += 1

print(min(cnt_1,cnt_0) * 2)

Measured memory_bytes: 23176
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <random>
#include <functional>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define MAP map<int,int>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e17;

void ANS(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Ans(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void ans(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
	string S;
	cin >> S;
	int gp = 0, score = 0;
	REP(i,S.size()){
		if (S[i] == 'g') {
			if (gp > 0) {
				gp--;
				score++;
			}
			else gp++;
		}
		if (S[i] == 'p'){
			if (gp > 0)	gp--;
			else {
				gp++;
				score--;
			}
		}
	}
	cout << score << endl;


	return 0;
}


Measured memory_bytes: 512
#!usr/bin/env python3

import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
            del tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
            del tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
            del tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp
            del tmp

    def spin_die_clockwise(self):
        tmp = self.pips[1]
        self.pips[1] = self.pips[2]
        self.pips[2] = self.pips[4]
        self.pips[4] = self.pips[3]
        self.pips[3] = tmp
        del tmp

    def get_upside(self):
        return self.pips[0]

    def get_frontside(self):
        return self.pips[1]

    def get_rightside(self):
        return self.pips[2]


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)
    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def main():
    die = init_die()
    q = int(sys.stdin.readline().strip('\n'))

    for question in range(q):
        q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]

        if q_pips[0] == die.pips[0]:
            pass
        elif q_pips[0] == die.pips[1]:
            die.move_die('N')
        elif q_pips[0] == die.pips[2]:
            die.move_die('W')
        elif q_pips[0] == die.pips[3]:
            die.move_die('E')
        elif q_pips[0] == die.pips[4]:
            die.move_die('S')
        elif q_pips[0] == die.pips[5]:
            die.move_die('N')
            die.move_die('N')

        while die.get_frontside() != q_pips[1]:
            die.spin_die_clockwise()

        print(die.get_rightside())


if __name__ == '__main__':
    main()

Measured memory_bytes: 7720