akhauriyash/Code-Regression huggingface dataset:
N = int(input())
h = [int(i) for i in input().split()]
dp = [10**4+1] * N

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,N) :
    a = dp[i-2]+abs(h[i-2]-h[i])
    b = dp[i-1]+abs(h[i-1]-h[i])
    dp[i] = min(a,b)

print(dp[-1])

Measured memory_bytes: 20332
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

ll numofbits5(ll bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

void solve()
{
    IN(n);
    bool* can = new bool[1<<n];
    rep(i, n)
    {
        IN(a);
        rep(j, a)
        {
            IN(x, y);
            for (int bit = 0; bit < (1<<n); ++bit)
            {
                if (bit & (1 << i))
                {
                    if ((bool)(bit & (1 << (x-1))) != y)
                    {
                        can[bit] = true;
                    }
                }
            }
        }
    }
    ll m = 0;
    for (int bit = 0; bit < (1<<n); ++bit)
    {
        if (!can[bit])
        {
            chmax(m, numofbits5(bit));
        }
    }
    cout << m << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> p;
#define MAX 3000
p map[MAX+1][2*MAX+3];

int main(void){
  vector<p> v;
  int N,T;
  cin >> N >> T;
  for(int i=0;i<N;i++){
    int A,B;
    cin >> A >> B;
    p tmp(A,B);
    v.push_back(tmp);
  }
  sort(v.begin(),v.end());
  for(int i=0;i<=2*MAX+2;i++){
    p tmp(0,0);
    //0個なら何もできない
    map[0][i] = tmp;
  }
  for(int n=1;n<=N;n++){
    // items
    int An = v[n-1].first;
    int Bn = v[n-1].second;
    //cout << An << " " << Bn << endl;
    for(int t=0;t<=2*MAX+2;t++){
      //注文できるなら
      if(t - An >= 0){
	int comp = map[n-1][t-An].first + Bn;
	int pre = map[n-1][t].first;
	if(comp >= pre && t-An < T){
	  map[n][t].first = comp;
	  map[n][t].second = t-An;
	  //cout << comp << endl;
	}else{
	  map[n][t] = map[n-1][t];
	}
	//cannot order :same to one of (n-1,t) 
      }else{
	map[n][t] = map[n-1][t];
      }
    }
  }
  // Nの段で　注文時間が間に合っている　かつ　最大のBを探す
  int max = 0;
  for(int t=0;t<=2*MAX+2;t++){
    p tmp = map[N][t];
    if(tmp.second < T && max < tmp.first){
      max = tmp.first;
      //cout << t << ":" << tmp.second << ":" << max << endl; 
    }
  }
  cout << max << endl;
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  if((s.at(0)==s.at(1) && s.at(2)==s.at(3) && s.at(0)!=s.at(2)) || (s.at(0)==s.at(2) && s.at(1)==s.at(3) && s.at(0)!=s.at(1)) || (s.at(0)==s.at(3) && s.at(1)==s.at(2) && s.at(0)!=s.at(1))){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
N = int(input())
L = []


def f(v: str):
    for i in list('357'):
        new_v = v + i
        if N < int(new_v):
            continue
        if new_v.count('3') >= 1 and new_v.count('5') >= 1 and new_v.count(
                '7') >= 1:
            L.append(new_v)
        f(new_v)


f('')
# print(f'{L=}')
ans = len(L)
print(ans)


Measured memory_bytes: 10760
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
   int p,q,r;
   cin >> p >> q >> r;
   cout << min({p + q, q + r, p + r}) << endl;

   return 0;
}

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

using namespace std;
int main(){
	string s;
	string t;
	int i,j,n,m,c;
	cin >> s >> t;
	n = s.size();
	m = t.size();
	if(n!=m){
		cout << "No" << endl;
		return 0;
	}
	
	for(i=0;i<n;i++){
		c = 0;
		int k = 0;
		for(j=i;j<i+n;j++){
			if(s[k]==t[j%n]){
				c++;
			}
			k++;
			if(c==n){
				cout << "Yes" << endl;
				return 0;;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

main = do
  [n, l] <- map (read::String -> Int) . words <$> getLine
  let index = 1 - l
      score = foldl (+) 0 $ map (\i -> l + i - 1) [1..n]
      ans = if index >= 1 && index <= n then score
            else if l < 0 then score - (l + n - 1)
            else score - l
  print ans
  

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

signed main(){

	lli n;
	cin>>n;

	map<lli,lli> cnt;
	REP(i,0,n){
		lli t;
		cin>>t;
		cnt[t]++;
	}

	lli ans = 0;
	for(auto e:cnt){
		if(e.second>=e.first){
			ans += e.second-e.first;
		}
		else{
			ans += e.second;
		}
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 6272
import java.util.Scanner;

public class Main {
    static int N;
    static int[] result;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        result = new int[N+1];
        f(N);

        for(int i = 1; i <= N; i++) {
            System.out.println(result[i]);
        }
    }
    static void f(int n) {

        for(int i = 1; i <= 101; i++) {
            for(int j = 1; j <= 101; j++) {
                for(int k = 1; k <= 101; k++) {
//                    if(i*i + j*j + k*k + i*j + i*k + j*k == n) {
//                        ++result[n];
//                    }
                    n=i*i + j*j + k*k + i*j + i*k + j*k;
                    if(n>N) break;
                    ++result[n];
                }
            }
        }
    }
}


Measured memory_bytes: 39080
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readarr(a, n) int a[(n) + 1] = {}; fori(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori(i, 1, n) {fori(j, 1, m) cin >> a[i][j];}
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define sort1(v) sort(v.begin(), v.end()) 
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;

const long long inf2 = (long long)1e18;
const long long mod = (long long)(1e9+7);
const long long inf1 =(long long)(1e6+1);

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

    string s;
    cin >> s;
    int n = s.length();
    s = " "+s;
    int c = 0;
    fori(i, 1, n/2) if(s[i] != s[n-i+1]) c++;
    cout << c;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <queue>
#include <vector>
#include <map>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int N;
map<ll, int> exps;

ll solve(map<ll, int>::iterator p, ll mul) {
    if (p == exps.end()) {
        if (mul == 1) return 1;
        else return 0;
    }
    ll res = 0;
    for (int i = 0; i < p->second + 1; ++i) {
        if (mul % (i+1) != 0) continue;
        res += solve(++p, mul / (i+1));
        --p;
    }
    return res;
}

int main() {
    cin >> N;
    for (int i = 2; i <= N; ++i) {
        auto ps = prime_factorize(i);
        for (auto it : ps) {
            exps[it.first] += it.second;
        }
    }
    cout << solve(exps.begin(), 75) << endl;
}



Measured memory_bytes: 256
//In the name of Allah

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long x, y;
  scanf("%lld %lld", &x, &y);
  if (x - y > -2 && 2 > x - y) {
    puts("Brown");
  }
  else {
    puts("Alice");
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <vector>
#include <tuple>
#include <algorithm>
#include <deque>

using namespace std;

using ll = long long;
int n, m;
int digits[9];
int sticks_for_digits[10] = {-1,2,5,5,4,5,6,3,7,6};
int digits_for_sticks[10] = {0};
bool called[10000];

struct Node {
  int value;
  Node *next;
};
Node *dp[10000];

bool is_left_ge(Node *left, Node *right)
{
  Node *l = left;
  Node *r = right;
  while (!((l == 0) && (r == 0))) {
    if (r == 0) return true;
    if (l == 0) return false;
    l = l->next;
    r = r->next;
  }
  l = left;
  r = right;
  while (!((l == 0) && (r == 0))) {
    if (l->value > r->value) return true;
    if (l->value < r->value) return false;
    l = l->next;
    r = r->next;
  }
  return true;
}

void solve(int sticks)
{
  if (called[sticks]) return;
  Node *cur = (Node *)0;
  //printf("entering solve(%d)\n", sticks);
  //cur.push_back(0);
  for (int i = 0; i < m; i++) {
    int to_consume = sticks_for_digits[digits[i]];
    if (sticks < to_consume) continue;
    solve(sticks-to_consume);
    /*printf("solve(%d) =", sticks-to_consume);
    Node *ptr = dp[sticks-to_consume];
    while (ptr) {
      printf("%d", ptr->value);
      ptr = ptr->next;
    }
    printf("\n");*/
    if (dp[sticks-to_consume] == 0) continue;
    Node *newnode = (Node *)malloc(sizeof (Node));
    newnode->value = digits[i];
    newnode->next = dp[sticks-to_consume];
    if (is_left_ge(newnode, cur)) {
      cur = newnode;
    }
    else {
      free(newnode);
    }
  }
  if (cur == 0) {
    int c = 0;
    for (int i = 0; i < m; i++) {
      if (sticks_for_digits[digits[i]] == sticks) {
        c = max(c, digits[i]);
      }
    }
    if (c != 0) {
      Node *newnode = (Node *)malloc(sizeof (Node));
      newnode->value = c;
      newnode->next = 0;
      cur = newnode;
    }
  }
  else if (cur->next == 0) {
    for (int i = 0; i < m; i++) {
      if (sticks_for_digits[digits[i]] == sticks) {
        cur->value = max(cur->value, digits[i]);
      }
    }
  }
  dp[sticks] = cur;
  called[sticks] = true;
}

int main()
{
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &(digits[i]));
    //int sticks = sticks_for_digits[digits[i]];
    //digits_for_sticks[sticks] = max(digits_for_sticks[sticks], digits[i]);
  }
  dp[0] = 0;
  called[0] = true;
  solve(n);
  Node *ptr = dp[n];
  vector<int> ds;
  while (ptr) {
    ds.push_back(ptr->value);
    ptr = ptr->next;
  }
  sort(ds.begin(), ds.end(), greater<int>());
  for (auto d : ds) {
    printf("%d", d);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 1280
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)
A,VA = mips()
B,VB = mips()
T = ii()
if A <= B:
    d1 = A + VA * T
    d2 = B + VB * T
    if d1 >= d2:
        print("YES")
    else:
        print("NO")
else:
    d2 = B - VB * T
    d1 = A - VA * T
    if d1 <= d2:
        print("YES")
    else:
        print("NO")

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

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

    int ans = a * x + b * y;
    ans = min(ans, c * 2 * max(x, y));
    if (x > y)
    {
        ans = min(ans, c * 2 * min(x, y) + (x - y) * a);
    }
    else
    {
        ans = min(ans, c * 2 * min(x, y) + (y - x) * b);
    }
    cout << ans << endl;
    return (0);
}


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

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

    if(n % 2 == 0){
        for(int i = n - 1;i >= 0;i--){
            if((i + 1) % 2 == 0){
                cout << a[i] << " ";
            }
        }

        for(int i = 0;i < n;i++){
            if((i + 1) % 2 != 0){
                cout << a[i] << " ";
            }
        }
    }
    else{
        for(int i = n - 1;i >= 0;i--){
            if((i + 1) % 2 != 0){
                cout << a[i] << " ";
            }
        }

        for(int i = 0;i < n;i++){
            if((i + 1) % 2 == 0){
                cout << a[i] << " ";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 2944
def maxHeapfy(A, i):
    l = i * 2
    r = i * 2 + 1
    if l <= H and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r <= H and A[r] > A[largest]:
        largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapfy(A, largest)

def buildMaxHeap(A, H):
    for i in range(H // 2, 0, -1):
        maxHeapfy(A, i)


H = int(input())

A = [None] + list(map(int, input().split()))

buildMaxHeap(A, H)

print('', *A[1:])

Measured memory_bytes: 66028
#include <bits/stdc++.h>
#define v(T) vector<T>
#define yn {puts("Yes");}else{puts("No");}
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const double eps = 1e-10;

int main() {
  int a, b;
  cin >> a >> b;
  if (a * b % 2 == 0)
    puts("Even");
  else
    puts("Odd");
  return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <tuple> 
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll, ll, ll> T;

int main(){
	ll N;
	cin >> N;
	vector<ll> a(N);
	vector<ll> b(N);
	vector<ll> c(N);
	for(int i=0;i<N;i++)
		cin >> a[i];
	for(int i=0;i<N;i++)
		cin >> b[i];
	for(int i=0;i<N;i++)
		cin >> c[i];
	sort(a.begin(), a.end());
	sort(c.begin(), c.end());
	ll ans = 0;
	for(int i=0;i<N;i++){
		auto l = lower_bound(a.begin(), a.end(), b[i]);
		auto r = upper_bound(c.begin(), c.end(), b[i]);
		ans += (l - a.begin()) * (c.end() - r);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N;
    string S, T, ans;
    cin >> N >> S >> T;
    for(int i=0; i<N; i++){
        ans += S[i];
        ans += T[i];
    }
    cout << ans << endl;
}

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

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  a.push_back(a.at(0) + k);
  int m = 0;
  for(int i = 0; i < n; i++) {
    m = max(m, a.at(i+1) - a.at(i));
  }
  cout << k - m << endl;
}

Measured memory_bytes: 4800
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
ll inf=1e10;

int main(){
  int A,B,K;
  cin>>A>>B>>K;
  int cnt(0);
  for (int i(min(A,B));i>0;i--){
    if (A%i==0&&B%i==0) cnt++;
    if (cnt == K) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long n, A;
vector<long long> x(55, 0);
long long dp[55][55][3300];

int main() {
    cin >> n >> A;
    for(int i = 0; i < n; ++i) cin >> x.at(i);

    dp[0][0][0] = 1;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= i; ++j) {
            for(int k = 0; k < 3300; ++k) {
                dp[i+1][j][k] += dp[i][j][k];
                if(k >= x.at(i)) dp[i+1][j+1][k] += dp[i][j][k-x.at(i)];
            }
        }
    }

    long long ans = 0;
    for(int j = 1; j <= n; ++j) {
        // cout << "j A*j " << j << " " << A*j << " " << dp[n][j][A*j] << endl;
        ans += dp[n][j][A*j];
    }

    cout << ans << endl;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll a;
  ll b;
  ll t;
  cin >> a >> b >> t;
  cout << b*(t/a) << endl;
  return 0;
}


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

int main(){
    long N, A;
    set<long> As;

    cin >> N;
    for(long i=0;i<N;i++){
        cin >> A;
        if(As.find(A) == As.end()){
            As.insert(A);
        }
        else{
            As.erase(A);
        }
    }
    cout << As.size() << endl;
    return 0;
}

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

int main() 
{
	int n;
	int x;
	int i;
	int sum = 0;
	int arr[100000];
	cin >> n >> x;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	sort(arr , arr+n);
	
	for ( i = 0; i < n; i++)
	{
		sum += arr[i];
		if(sum > x)
		{
			break;
		}
	}
	if(sum < x)
	{
		i--;
	}
	cout << i;
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int i=0;
    //べき乗数を後ろから探す
    for(i=X;i>0;i--){
      if(judge(i)){
        break;
      }
    }
    System.out.println(i);
  }
    //べき乗数かどうか
    private static boolean judge(int n){
      boolean re = false;
      if(n==1){//１のとき
        re = true;
      }else{//１以外なら
        for(int i=2;i<n;i++){
          for(int j=1;j<n;j++){
            int m = (int)Math.pow(i,j);
            if(m==n){
              re = true;
              break;
            }
          }
        }
      }
        return re;
      }
}

Measured memory_bytes: 35692
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
typedef long long ll;
const int MYINF = 1e9+7;
typedef int bool;
bool true = 1;
bool false = 0;
 
int n, k;
int w[100010];
 
bool check(int capa) {
    int i, j, c;
    for (i = 0, j = 0; j < k; j++) {
        c = capa;
        while ((c - w[i]) >= 0) {
            c -= w[i];
            i++;
            if (i == n) {
                return true;
            }
        }
    }
    if (i == n) return true;
    return false;
}
 
int search(int l, int r) {
    int i, m;
    if (r - l < 5) {
        for (i = l - 1; i <= r + 1; i++) {
            if (check(i)) return i;
        }
    }
    m = (l + r) / 2;
    if (check(m)) {
        return search(l, m - 1);
    } else {
        return search(m + 1, r);
    }
}
 
int main(int argc, char **argv)
{
    int i, maxw, pd, d;
    scanf("%d %d", &n, &k);
    maxw = -1;
    for (i = 0; i < n; i++) {
        scanf("%d", &w[i]);
        if (maxw < w[i]) maxw = w[i];
    }
 
    if (k >= n) {
        printf("%d\n", maxw);
        return 0;
    }
 
    for (pd = d = maxw; !check(d); pd = d, d *= 2)
        ;
    printf("%d\n", search(pd, d));
 
    return 0;
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  rep(i, 0, n) {
    int check;
    cin >> check;
    if (check >= k) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,k;
    cin>>n>>k;
    ll ans=1;
     for(int i=1;i<=n;i++)
     {
      if(ans*2<ans+k)
      {
        ans*=2;
      }
      else
      {
        ans+=k;
      }
     }
cout<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int mo = 1e9 + 7,N = 2e5 + 10, S = 4010, Z = 2000;
int a[N],b[N];
ll f[S][S];
ll jc[N],inv[N];
int n;
ll ksm(ll x,ll y) {
	ll ret = 1;  for (; y; y>>=1) {
		if (y & 1)ret = ret * x % mo;
		x = x * x % mo;
	}
	return ret;
}
ll ans;
ll C(ll n, ll m) {
	if (n<m) return 0;
	return jc[n] % mo * inv[m] % mo * inv[n-m] % mo;
}
void add(ll &x,ll y) {
	if(x+y>=mo) x=x+y-mo; else x=x+y;
}
int main() {
	cin>>n;
	jc[0]=1;for (int i = 1; i < N; i++) jc[i] = jc[i-1] * i % mo;
	inv[N-1] = ksm(jc[N-1], mo - 2);
	for (int i = N - 2; ~i; i--) inv[i] = inv[i+1] * (i+1) % mo;
	for (int i = 1; i <= n; i++) {
		scanf("%d %d",&a[i],&b[i]);
		f[Z-a[i]][Z-b[i]]++;
		ans=(ans - C((a[i]+b[i])*2,a[i]*2)) % mo;
	}
	for (int i = 0; i <= 4000; i++)
	for (int j = 0; j <= 4000; j++) {
		if (i) add(f[i][j],f[i-1][j]);
		if (j) add(f[i][j],f[i][j-1]);
	}
	for (int i = 1; i <= n; i++) {
		ans=(ans + f[Z+a[i]][Z+b[i]]) % mo;
	}
	ans = ans * ((mo+1)/2) % mo;
	printf("%lld",(ans+mo)%mo);
}

Measured memory_bytes: 130560
#include <iostream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MAXN 0x7fffffff
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define PF(X) push_front(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
#define PI  3.14159265358979
typedef long long ll;
typedef pair<int,int> PII;
typedef priority_queue<int,vector<int>,greater<int> > PQI;
typedef vector<PII> VII;
typedef vector<int> VI;
#define X first
#define Y second

queue<int> *st;
stack<int> *LQ;
stack<int> *RQ;
VI v; 

void dfs(int x)
{
	int flag=0;
	if(LQ->empty() || (!LQ->empty() && x>LQ->top()))
	{
		LQ->push(x);
		flag=1;
	}
	if((RQ->empty() || (!RQ->empty() && x>RQ->top())) && !flag)
	{
		RQ->push(x);
		flag=1;
	}
	if(!flag)
		return ;
	st->pop();
	dfs(st->front());
}
	

int main()
{
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		queue<int> stemp;  st=&stemp;
		stack<int> LQtemp; LQ=&LQtemp;
		stack<int> RQtemp; RQ=&RQtemp;
		REP(i,10)
		{
			int x;
			cin>>x;
			st->push(x);
		}
		dfs(st->front());
		/*cout<<endl;
		while(!LQ->empty())
		{
			int x=LQ->top();
			cout<<x<<endl;
			LQ->pop();
		}
		cout<<endl;
		while(!RQ->empty())
		{
			int x=RQ->top();
			cout<<x<<endl;
			RQ->pop();
		}*/
		if(st->empty())
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

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

const long long mod = 1000000007;

int main() {
  long long N;
  cin >> N;
  vector<long long> C(N);
  for(int i=0;i<N;i++) cin >> C[i];
  sort(C.begin(),C.end());
  reverse(C.begin(),C.end());
  
  long long ans=0;
  for(int i=0;i<N;i++){
    ans += (C[i]*(i+2))%mod;
    ans %= mod;
  }
  for(int i=0;i<2*N-2;i++){
    ans *= 2;
    ans %= mod;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c;
    cin >> a >> b >> c;
    while(a != 0){
        vector<int> A(a,0),B(b,0),C(c,0);
        int N;
        cin >> N;
        vector<int> N1(N,-1),N2(N,-1),N3(N,-1),N4(N);
        for(int i=0; i<N; i++){
            cin >> N1[i] >> N2[i] >> N3[i] >> N4[i];
            N1[i]--;
            N2[i]--;
            N3[i]--;
        }
        for(int i=0; i<N; i++){
            if(N4[i] == 1){
                A[N1[i]] = 1;
                B[N2[i]-a] = 1;
                C[N3[i]-(a+b)] = 1;
            }
        }
        for(int i=0; i<N; i++){
            if(N4[i] == 0){
                int cnt = 0;
                cnt += A[N1[i]];
                cnt += B[N2[i]-a];
                cnt += C[N3[i]-(a+b)];
                if(cnt >= 2){
                    if(A[N1[i]] != 1) A[N1[i]] = -1;
                    if(B[N2[i]-a] != 1) B[N2[i]-a] = -1;
                    if(C[N3[i]-(a+b)] != 1) C[N3[i]-(a+b)] = -1;
                }
            }
        }
        for(int i=0; i<a; i++){
            if(A[i] == 1){
                cout << 1 << enld;
            }else if(A[i] == 0){
                cout << 2 << enld;
            }else{
                cout << 0 << enld;
            }
        }
        for(int i=0; i<b; i++){
            if(B[i] == 1){
                cout << 1 << enld;
            }else if(B[i] == 0){
                cout << 2 << enld;
            }else{
                cout << 0 << enld;
            }
        }
        for(int i=0; i<c; i++){
            if(C[i] == 1){
                cout << 1 << enld;
            }else if(C[i] == 0){
                cout << 2 << enld;
            }else{
                cout << 0 << enld;
            }
        }
        cin >> a >> b >> c;
    }
    return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  rep(i, B) {
    if (A*(i+1) % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
bool check(int a,int b,int c){
	return a+b+c>=22;
} 
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(check(a,b,c)) printf("bust\n");
	else printf("win\n");
	return 0;
}

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
std::string s;
int sum[200005];
int main() {
	std::cin >> n;
	std::cin >> s;

	for (int i = 0; i < n; ++i) {
		sum[i + 1] = sum[i];
		if (s[i] == '#')
			++sum[i + 1];
	}

	int ans = inf;
	for (int i = 0; i <= n; ++i)
		ans = std::min(ans, sum[i] + n - i - (sum[n] - sum[i]));

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


Measured memory_bytes: 1412
#include <iostream>

using namespace std;

int main()
{
    int n, m;
    std::cin >> n >> m;
    for(int i = 1; 2 * i < m + 2; ++i){
        cout << i << " " << m + 2 - i << "\n";
    }
    for(int i = m + 2; 2 * i < 3 * m + 3; ++i){
        cout << i << " " << 3 * m + 3 - i << "\n";
    }
}

Measured memory_bytes: 3636
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		int array[] = new int[10];
		for(int i = 0; i < 10; i++){
			array[i] = scan.nextInt();
		}
		Arrays.sort(array);
		for(int i = array.length - 1; i > array.length - 4; i--)
			System.out.println(array[i]);
	}
}

Measured memory_bytes: 17168
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> result(N);
  for (int i = 0; i < N; i++)
    cin >> result.at(i);
  sort(result.begin(),result.end());
  int count = 1;
  for (int i = 0; i < N - 1; i++){
    if (result.at(i) != result.at(i + 1))
    count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>

int main(void)
{
    int K, N;

    scanf("%d", &K);
    scanf("%d", &N);
    int A[N], B[N], n;
    n = N - 1;
    for(int i = 0; i < N; i++)
    {
        scanf("%d", &A[i]);
    };
    int l, m, d, D = 0;
    for(int j = 0; j < n; j++)
    {
        m = j + 1;

       d =  A[m] - A[j];

       if(D < d)
            D = d;
    };

    if(D < K - A[n] + A[0])
        D = K - A[n] + A[0];
    
    printf("%d\n", K - D);

    return 0;
}

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


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		double[] v = new double[N];
		for (int i=0;i<N;i++) {
			v[i] = Double.parseDouble(sc.next());
		}
		Arrays.sort(v);
		double ans = v[0];
		for (int i=1;i<N;i++) {
			ans = (ans+v[i])/2;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
N, M = map(int, input().split())
X = set()
Y = set()

ABC = []
for _ in range(N):
    # (A,C)-(B,C)
    A, B, C = map(int, input().split())
    X.add(A)
    X.add(B)
    Y.add(C)
    ABC.append((A,B,C))

DEF = []
for _ in range(M):
    # (D,E)-(D,F)
    D, E, F = map(int, input().split())
    X.add(D)
    Y.add(E)
    Y.add(F)
    DEF.append((D,E,F))

XL = sorted(list(X))
YL = sorted(list(Y))

XD = {k:v for v,k in enumerate(XL)}
YD = {k:v for v,k in enumerate(YL)}

nX = len(XL)+1
nY = len(YL)+1

S = [[False]*nY for _ in range(nX)]
T = [[15]*nY for _ in range(nX)]

for a, b, c in ABC:
    xbgn = XD[a]+1
    xend = XD[b]
    yu   = YD[c]
    yd   = yu+1
    for x in range(xbgn, xend+1):
        T[x][yu]-=4
        T[x][yd]-=8

for d, e, f in DEF:
    ybgn = YD[e]+1
    yend = YD[f]
    xl   = XD[d]
    xr   = xl+1
    for y in range(ybgn, yend+1):
        T[xl][y]-=1
        T[xr][y]-=2

x0 = 0
while XL[x0]<0 and x0<nX-2: x0+=1
y0 = 0
while YL[y0]<0 and y0<nY-2: y0+=1

queue = [(x0, y0)]

ans = 0
while queue:
    queue_new = []
    for qx, qy in queue:
        if S[qx][qy]: continue
        S[qx][qy]=True
        if qx==0 or qy==0 or qx==nX-1 or qy==nY-1:
            print('INF')
            exit()

        ans += (XL[qx]-XL[qx-1])*(YL[qy]-YL[qy-1])

        t = T[qx][qy]
        if t&1: queue_new.append((qx+1,qy))
        if t&2: queue_new.append((qx-1,qy))
        if t&4: queue_new.append((qx,qy+1))
        if t&8: queue_new.append((qx,qy-1))

    queue = queue_new


print(ans)


Measured memory_bytes: 216544
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();

		boolean flag = false;
		for (int i = 0; i <= x; i++) {
			if (4 * i + 2 * (x - i) == y) {
				flag = true;
			}
		}

		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}

Measured memory_bytes: 35756
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int):
    # 候補を二つ
    X1 = int(N/1.08)
    X2 = int(N/1.08)+1

    if int(X1*1.08) == N:
        print(X1)
    elif int(X2*1.08) == N:
        print(X2)
    else:
        print(":(")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    vector<int> t(N+3);
    t[0] = 0; t[1] = 0;
    FOR(i, 2, N+2){
        cin >> t[i];
        t[i] += t[i-1];
    }
    t[N+2] = t[N+1];
    vector<int> v(N+2);
    v[0] = 0;
    REP(i, N) cin >> v[i+1];
    v[N+1] = 0;
    
    int E = t[N+2];
    vector<double> mx(2*E+1);
    fill(All(mx), INF);
    REP(i, N+2){
        int l = t[i]*2;
        int r = t[i+1]*2;
        REP(j, 2*E+1){
            if(j < l){
                mx[j] = min(mx[j], v[i]+(l-j)*(.5));
            }else if(l <= j && j <= r){
                mx[j] = min(mx[j], (double)v[i]);
            }else{
                mx[j] = min(mx[j], v[i]+(j-r)*(.5));
            }
        }
    }
    double ans = 0;
    // REP(i, 2*E+1){
    //     cout << mx[i] << "\n";
    // }
    REP(i, 2*E){
        ans += (double)(mx[i]+mx[i+1])*(1/4.);
    }

    cout << setprecision(14) << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
s = list(input())
#key =s.copy()
#print(s)
a = []
#count = 0

for i in s:
 # print(s)
  if i == 'B':
    a = a[:-1]
    #del a[-1]
  else:
    a.append(i)
  
    
print(''.join(a))    
    

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

ll count_disjoint_sets;

ll n;
vector<ll> Arr, size;

void weighted_initialize()
{
    count_disjoint_sets = n;
    Arr.resize(n + 1), size.resize(n + 1, 1);
    for (ll i = 1; i <= n; i++)
    {
        Arr[i] = i;
        size[i] = 1;
    }
}

ll root(ll i)
{
    while (Arr[i] != i)
    {
        i = Arr[i];
    }
    return i;
}

ll weighted_union(ll A, ll B)
{
    ll root_A = root(A);
    ll root_B = root(B);
    if (root_A == root_B)
    {
        return 0;
    }
    ll ret = size[root_A] * size[root_B];
    if (size[root_A] < size[root_B])
    {
        Arr[root_A] = root_B;
        size[root_B] += size[root_A];
    }
    else
    {
        Arr[root_B] = root_A;
        size[root_A] += size[root_B];
    }
    count_disjoint_sets--;
    return ret;
}

bool weighted_find(ll A, ll B)
{
    return root(A) == root(B);
}

int main()
{
    cin >> n;
    weighted_initialize();
    ll m;
    cin >> m;
    using pii = pair<ll, ll>;
    ll in_sum = (n * (n - 1)) / 2;
    vector<pii> v(m);
    for (ll i = 0; i < m; ++i)
    {
        cin >> v[i].first >> v[i].second;
    }
    vector<ll> res;
    for (int i = m - 1; i >= 0; --i)
    {
        res.push_back(in_sum);
        ll temp = weighted_union(v[i].first, v[i].second);
        in_sum -= temp;
    }
    for (int i = m - 1; i >= 0; --i)
    {
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 6136
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        v[i] -= i;
    }

    sort(v.begin(), v.end());

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += abs(v[i] - v[n / 2]);
    }
    cout << ans << endl;
}


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

const int N=100005;
const long long MOD=1e9+7;
int n;
long long dp[N],f[N],a[20][20];
char str[N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			scanf("%lld",&a[i][j]);
		}
	}
	for(int i=1;i<(1<<n);i++)
	{
		int x=log2(i&-i)+1;
		dp[i]=dp[i-(i&-i)];
		for(int j=x+1;j<=n;j++)
		{
			if((i&(1<<j-1))) dp[i]+=a[j][x];
		}
	}
	for(int i=1;i<(1<<n);i++)
	{
		for(int j=i;j>0;j=(j-1)&i)
		{
			f[i]=max(f[i],f[i-j]+dp[j]);
		}
	}
	printf("%lld\n",f[(1<<n)-1]);
}

Measured memory_bytes: 1280
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
p = list(map(int, input().split()))
swappair= [list(map(int, input().split())) for _ in range(M)]

union_list = [-1 for _ in range(N+1)]

def find(a): # get root
    while not union_list[a] == -1:
        a = union_list[a]
    return a

def merge(a,b): 
    ia = find(a)
    ib = find(b)
    if ia == ib:
        return 
        
    if ia < ib:
        union_list[ib] = ia
    elif ia > ib:
        union_list[ia] = ib
    


def is_same_grp(a,b):
    ia = find(a)
    ib = find(b)
    return ia == ib

for i in range(M):
    merge(*swappair[i])

ans = 0
for i in range(1,N+1):
    ans += int( is_same_grp(i, p[i-1]))

print(ans)




Measured memory_bytes: 77420
l,r=map(int,input().split())
if r-l>=2019:
  print(0)
  exit()
m0=l%2019
m1=r%2019
if m1<m0:
  print(0)
  exit()
else:
  ans=2019
  for i in range(m0,m1):
    for j in range(i+1,m1+1):
      ans=min(ans,i*j%2019)
  print(ans)


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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    int a = 0;
    for (int i = 0; i < n; i++) {
        cin >> vec[i];
        a += vec[i];
    }
    int b = 0;
    int res = 100000;
    for (int i = 0; i < n; i++) {
        b += vec[i];
        a -= vec[i];
        res = min(res, abs(a-b));
    }
    cout << res << endl;
}



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

using ll =  long long;
using pint =  pair<int,int>;

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義 #define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//lambda: [&](int x, int y){return x<y;}

signed main(void){
    int h,n;cin>>h>>n;
    vint a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];

    vvint dp(n+1,vint(h+10,INT_MAX));
    dp[0][0]=0;
    rep(i,n){
        rep(j,h+2){
            if(j<a[i]){
                dp[i+1][j]=min(dp[i+1][j],min(dp[i][j],b[i]));
            }else dp[i+1][j]=min(dp[i][j],dp[i+1][j-a[i]]+b[i]);
        }
    }
    cout << dp[n][h] << endl;
}


Measured memory_bytes: 39424
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        if(!s.equals("AAA")&&!s.equals("BBB")){
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}

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

int main(){
  string S;
  cin >> S;
//string S = Sa + 'U';
  
  bool boo = true;
  rep(i, S.size()){
    if(i%2 == 0){
      if(!(S[i] == 'R' || S[i] == 'U' || S[i] == 'D')){
      boo = false;
      break;
      }
    }
    if(i%2 == 1){
      if(!(S[i] == 'L' || S[i] == 'U' || S[i] == 'D')){
      boo = false;
      break;
      }
    }
  }
  if(boo) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int INF = -1e9-100;

signed main(){
  int N, K; cin >> N >> K;
  vector<int> A(N);
  int ans = INF;
  for(int i = 0; i < N; i++) cin >> A[i];
  for(int a = 0; a <= K; a++){
    for(int b = 0; b <= K; b++){
      if(a + b > min(N, K)) continue;
      vector<int> data;
      int ans1 = 0;
      for(int i = 0; i < a; i++) ans1 += A[i], data.push_back(A[i]);
      for(int i = N - 1; i > N - 1 - b; i--) ans1 += A[i], data.push_back(A[i]);
      sort(data.begin(), data.end());
      for(int i = 0; i < min(K - a - b, a + b); i++) if(data[i] < 0) ans1 -= data[i];
      ans = max(ans, ans1);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640