akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("POSSIBLE")  # type: str


def no():
    print("IMPOSSIBLE")  # type: str


import heapq
INF = float("inf")


# 無向グラフを仮定する。
class Graph(object):
    def __init__(self, N):
        self.N = N
        self.V = list(range(N))
        self.E = [[] for _ in range(N)]

    def add_edge(self, edge):
        """辺を加える。edgeは(始点, 終点、重み)からなるリスト
        重みがなければ、重み1とする。
        """
        if len(edge) == 2:
            edge.append(1)
        elif len(edge) != 3:
            print("error in add_edge")
            pass

        s, t, w = edge
        self.E[s].append([t, w])
        self.E[t].append([s, w])  # 無向グラフを仮定。逆向きにも辺を張る

        pass


def shortestPath(g: Graph, s: int):
    """ グラフgにおいて、始点sから各頂点への最短路を求める
    引数
    g: グラフ, s: 始点
    返り値
    dist: 始点からの距離が格納されたリスト
    prev: 始点から最短経路で移動する場合、各頂点に至る前の頂点のリスト
    """
    dist = [INF]*g.N
    dist[s] = 0

    prev = [None]*g.N
    Q = []
    heapq.heappush(Q, (dist[s], s))

    while len(Q) > 0:
        _, u = heapq.heappop(Q)
        for v, w in g.E[u]:
            if dist[v] > dist[u] + w:
                dist[v] = dist[u] + w
                prev[v] = u
                heapq.heappush(Q, (dist[v], v))
    return dist, prev


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    g = Graph(N)
    for aa, bb in zip(a, b):
        g.add_edge([aa-1, bb-1, 1])

    dist, prev = shortestPath(g, 0)
    if dist[N-1] <= 2:
        yes()
    else:
        no()
    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
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 106712
n = int(input())
mon = 1000
sto = 0
A = list(map(int,input().split()))
for i in range (n):
    if i == n-1:
        mon += sto * A[i]
    elif A[i+1] > A[i]:
        buy = mon//A[i]
        sto += buy
        mon -= buy * A[i]
    elif A[i+1] < A[i]:
        mon += sto * A[i]
        sto = 0
print(mon)

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

int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  set<string> s;
  for(int i=0;i<n;i++){
    cin >> v[i];
    s.insert(v[i]);
  }
  cout << s.size();
}


Measured memory_bytes: 25072
#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int64_t intl;


int main(){
  int N,M,K,A;
  int count=0;
  cin >> N >> M;
  vector<bool> F(M,1);
  vector<bool> tempF(M,0);
  
  Rep(i,N){
    cin >> K;
    Rep(j,K){
      cin >> A;
      tempF.at(A-1) = 1;
    }
    
    Rep(h,M){
      F.at(h) = F.at(h) * tempF.at(h);
      tempF.at(h) = 0;
    }
  }
  
  Rep(h,M){
    if ( F.at(h) ) { count ++;}
  }
  cout << count;
}

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

#define loop(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;
struct __{__(){ios_base::Init i;ios_base::sync_with_stdio(0);cin.tie(0);}}__;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

int main() {
	int a = nxt(), b=nxt(), c=nxt();
	int k = nxt();

	while (k && b <= a){
		b *= 2;
		--k;
	}

	while (k && c <= b){
		c *= 2;
		--k;
	}

	if (b > a && c > b){
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}

	return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);


  vector<string> v(2); rep(i, 0, 2){ cin >> v[i]; }
  reverse(all(v[1]));
  YES(v[0]==v[1]);


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,d;
int x[15][15];
int ans;
int main()
{
	cin>>n>>d;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<d;j++)
			cin>>x[i][j];
	}
	for(int a=0;a<n;a++)
	{
		for(int b=0;b<a;b++)
		{
			int dist=0,d1=0;
			for(int i=0;i<d;i++)
			{
				d1+=(x[a][i]-x[b][i])*(x[a][i]-x[b][i]);
			}
			dist=sqrt(d1);
			if(dist*dist==d1)
				ans++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char a[10] = {};
char b[10] = {};
char c[10] = {};

int main()
{
	int a_length, b_length, c_length;
	char a_first, a_last;
	char b_first, b_last;
	char c_first, c_last;
	scanf("%s %s %s", a, b, c);
	//get length
	a_length = strlen(a);
	b_length = strlen(b);
	c_length = strlen(c);
	//get first and last
	a_first = a[0];
	a_last = a[a_length-1];
	b_first = b[0];
	b_last = b[b_length-1];
	c_first = c[0];
	c_last = c[c_length-1];
	//check first = last
	if (a_last == b_first && b_last == c_first)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int i,j,x,a,b,a1,b1,s,minx=1000000;
	cin>>x>>a>>b;
	b1=x/b;
	for(j=1;j<=b1;j++)
	{
		s=x-(a+b*j);
		if(s>=0&&s<minx) minx=s;
	}
	cout<<minx<<endl;
}

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

using namespace std;

#define N 10010

int A[N][N];

int main()
{
	int r, c, x, i;
	scanf("%d %d", &r, &c);
	
	vector<int> v;
	
	for(i = 0; i < r; i++)
	{
		x = 0;
		
		for(int j = 0; j < c; j++)
		{
			scanf("%d", &A[i][j]);
			x += A[i][j];
		}
		v.push_back(x);
	}
	
	for(i = 0; i < r; i++)
	{
		for(int j = 0; j < c; j++)
			printf("%d ", A[i][j]);
		printf("%d\n", v[i]);
	}
	
	int total = 0;
	vector<int> v2;
	
	for(i = 0; i < c; i++)
	{
		x = 0;
		
		for(int j = 0; j < r; j++)
		{
			x += A[j][i];
		}
		total += x;
		v2.push_back(x);
	}
	
	v2.push_back(total);
	
	for(i = 0; i < c; i++)
		printf("%d ", v2[i]);
	printf("%d\n", v2[i]);
			
	return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n,k;
	vector<int> genre[10];
	int dp[11][2001] = {};
	cin >> n >> k;
	for(int i = 0;i < n;i++){
		int a,b;
		cin >> a >> b;
		genre[b - 1].push_back(a);
	}
	for(int i = 0;i < 10;i++) {
		sort(genre[i].begin(),genre[i].end(),greater<int>());
		for(int j = 1;j < genre[i].size();j++){
			genre[i][j] += genre[i][j - 1] + 2 * j;
		}
	}
	
	for(int i = 1;i < 11;i++) {
		for(int j = 1;j <= n;j++){
			for(int k = 0;k <= min(j,(int)genre[i - 1].size());k++){
				if(k == 0) dp[i][j] = dp[i - 1][j];
				else dp[i][j] = max(dp[i][j],dp[i - 1][j - k] + genre[i - 1][k - 1]);
			}
		}
	}
	cout << dp[10][k] << endl;
	return 0;
}

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

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

  int N;
  cin >> N;
  int A[N];
  map<int, int> mp1, mp2;
  rep(i, N){
    cin >> A[i];
    if(i % 2 == 0){
      mp1[A[i]]++;
    }
    else{
      mp2[A[i]]++;
    }
  }
  pair<int, int> P1[N/2], P2[N/2];
  int i = 0;
  for(pair<int, int> P : mp1){
    P1[i].first = P.second;
    P1[i].second = P.first;
    i++;
  }
  int j = 0;
  for(pair<int, int> P : mp2){
    P2[j].first = P.second;
    P2[j].second = P.first;
    j++;
  }
  sort(P1, P1+i);
  reverse(P1, P1+i);
  sort(P2, P2+j);
  reverse(P2, P2+j);
  if(i == 1 && j == 1){
    if(P1[0].second == P2[0].second){
      cout << N/2 << endl;
      return 0;
    }
    else{
      cout << 0 << endl;
      return 0;
    }
  }
  else if(i == 1){
    if(P1[0].second == P2[0].second){
      cout << N/2 - P2[1].first << endl;
      return 0;
    }
    else{
      cout << N/2 - P2[0].first << endl;
      return 0;
    }
  }
  else if(j == 1){
    if(P1[0].second == P2[0].second){
      cout << N/2 - P1[1].first << endl;
      return 0;
    }
    else{
      cout << N/2 - P1[0].first << endl;
      return 0;
    }
  }
  else{
    if(P1[0].second != P2[0].second){
      cout << N - (P1[0].first + P2[0].first) << endl;
    }
    else{
      int a = max(P1[0].first + P2[1].first, P1[1].first + P2[0].first);
      cout << N - a << endl;
    }
  }
}

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

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


int main(){
  ll n;
  cin >> n;
  vector<ll> f(n+5,1);
  for(ll i = 2; i <= n; i++){
    for(ll j = 1; i*j <= n; j++){
      f[i*j]++;
    }
  }

  ll ans = 0;
  for(ll i = 1; i <= n; i++){
    ans += i*f[i];
  }

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



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

int main() {
  int s, s1, s2, s3;

  cin >> s;
  s1=s/100;
  s2=(s-s1*100)/10;
  s3=(s-s1*100-s2*10);
  cout << s1+s2+s3 << endl;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	int nac = 0, nwa = 0, ntle = 0, nre = 0;
	while(n--) {
	    cin >> s;
  	    if (s == "AC") nac++;
  	    else if (s == "WA") nwa++;
  	    else if (s == "TLE") ntle++;
  	    else nre++;
  	}
	cout << "AC x " << nac << endl;
	cout << "WA x " << nwa << endl;
	cout << "TLE x " << ntle << endl;
	cout << "RE x " << nre << endl;
	return 0;
}

Measured memory_bytes: 3576
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

#ifdef LOCAL
#include "local.h"
#endif

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)
#define ten(n) ((long long)(1e##n))

template <typename T, typename U> void upmin(T& a, const U& b) { a = min<T>(a, b); }
template <typename T, typename U> void upmax(T& a, const U& b) { a = max<T>(a, b); }
template <typename T> void uniq(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

typedef long long ll;
typedef pair<int, int> pint;

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

template <class T>
vector<T> divisors(T n)
{
    vector<T> res;
    for (T i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            res.push_back(i);
            if (i != n / i)
                res.push_back(n / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

ll gcd(ll a, ll b) { return b ? __gcd(b, a % b) : a; }
int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    rep(i, n)
        cin >> a[i];
    rep(i, m)
        cin >> b[i];

    vector<ll> cand;
    rep(i, a.size())
    {
        vector<ll> divs = divisors(a[i]);
        rep(di, divs.size())
        {
            ll div = divs[di];
            bool ok = true;
            rep(j, a.size())
            {
                if (a[j] % div != 0)
                {
                    ok = false;
                    break;
                }
            }
            if (ok)
                cand.push_back(div);
        }
    }
    uniq(cand);

    int res = 0;
    rep(ci, cand.size())
    {
        ll x = cand[ci];
        bool ok = true;
        rep(i, b.size())
        {
            if (x % b[i] != 0)
            {
                ok = false;
                break;
            }
        }
        if (ok)
            ++res;
    }
    cout << res << endl;
}


Measured memory_bytes: 1376
#include <bits/stdc++.h>
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define ld long double
#define el '\n'
#define PI (ld)3.14159265358979323846
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < int(n); i++)
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

/*vector<int> parent, rak;

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rank[a]+=rank[b];
    }
}*/

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

/*const int N = 1000001;
int lp[N+1];
vector<int> pr;
void s(){
for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}*/


ll kv;
ll t,n,x,y,h,k,z,p,q,w;

//vector<vector<ll>>v;
//vector<ll>vis,d;

int main() {
    IOS;
    cin>>x>>y>>p>>q;
    cout<<x*y-y*p-x*q+p*q;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  lvector A(n,0);
  map<ll,ll> mp;
  rep(i,n) {cin>>A[i];mp[A[i]]++;}
  sort(A.begin(),A.end());
  ll posl=0,posr=n-1;
  while(posl<posr-1) {
    if(mp[A[posl]]==1) {posl++;continue;}
    if(mp[A[posr]]==1) {posr--;continue;}
    if(mp[A[posl]]>1&&mp[A[posr]]>1) {
      A[posl]=-1,posl++,mp[A[posl]]--;
      A[posr]=-1,posr--,mp[A[posr]]--;
    }
  }
  for(ll i:A) if(i>0) ans++;
  for(auto i:mp) {
    if(i.second>1) ans-=2*(i.second-1);
  }
  ans=max(ans,0ll);
  print(ans);
  return 0;
}


Measured memory_bytes: 7296
c11, c12, c13 = list(map(int, input().split()))
c21, c22, c23 = list(map(int, input().split()))
c31, c32, c33 = list(map(int, input().split()))

ans = 'Yes'
if c12-c11 != c22-c21 or c22-c21 != c32-c31 or c32-c31 != c12-c11:
    ans = 'No'
if c13-c12 != c23-c22 or c23-c22 != c33-c32 or c33-c32 != c13-c12:
    ans = 'No'
if c21-c11 != c22-c12 or c22-c12 != c23-c13 or c23-c13 != c21-c11:
    ans = 'No'
if c31-c21 != c32-c22 or c32-c22 != c33-c23 or c33-c23 != c31-c21:
    ans = 'No'    
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;
typedef long long ll;
int dp[1000][1000] = {0};

int main()
{
	while (true)
	{
		int n;
		cin >> n;
		if (n == 0)
			break;

		int r[1000];
		int w[1000];
		int rsum = 0, rmax = 0, wsum = 0, rmaxid;
		for (int i = 0; i < n; i++)
		{
			cin >> r[i] >> w[i];
			if (rmax < r[i])
			{
				rmax = r[i];
				rmaxid = i;
			}
			rsum += r[i];
			wsum += w[i];
		}
		if (rmax * 2 <= rsum)
		{
			cout << rsum + wsum << endl;
			continue;
		}
		int m = rmax * 2 - rsum;
		if (m >= wsum - w[rmaxid])
		{
			cout << rmax * 2 + w[rmaxid] << endl;
			continue;
		}
		if (rmaxid)
			for (int i = w[0]; i <= m; i++)
				dp[0][i] = w[0];

		for (int i = 1; i < n; i++)
		{
			if (rmaxid == i)
			{
				for (int j = 0; j <= m; ++j)
					dp[i][j] = dp[i - 1][j];

				continue;
			}
			for (int j = 0; j <= m; j++)
			{
				dp[i][j] = max(dp[i - 1][j], (j >= w[i]) ? dp[i - 1][j - w[i]] + w[i] : 0);
			}
			if (dp[i][m] == m)
			{
				dp[n - 1][m] = m;
				break;
			}
		}
		cout << rmax * 2 + wsum - dp[n - 1][m] << endl;
	}
	return 0;
}

Measured memory_bytes: 1784
N = int(input())
a = [int(i) for i in input().split()]

ki = 0
gu_2 = 0
gu_4 = 0

for i in a:
    if i % 4 == 0:
        gu_4 += 1
    elif i % 2 == 0:
        gu_2 += 1
    else:
        ki += 1

if ki <= gu_4:
    print('Yes')
else:
    if gu_4 + 1 == ki and gu_4 + ki == N:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 20044
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N;
string str;
int S[MAX_N];
ll c[26];

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

  cin >> N;
  cin >> str;

  rep(i, N) {
      S[i] = str[i]-'a';
  }

  rep(i, N) {
      ++c[S[i]];
  }

  
  ll ans = 1;
  
  rep(i, 26) {
      ans = mod(ans*(c[i]+1), MOD);
  }

  ans = mod(ans-1, MOD);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1464
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main() {
	int H, W;
	while (cin >> H >> W && (H || W)) {
		for (int i = 0; i < W; i++)
			cout << "#";
		cout << endl;
		for (int i = 1; i < H - 1; i++) {
			cout << "#";
			for (int j = 1; j < W - 1; j++)
				cout << ".";
			cout << "#" << endl;
		}
		for (int i = 0; i < W; i++)
			cout << "#";
		cout << endl;
		cout << endl;
	}
}

Measured memory_bytes: 3080
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        String result = "Rainy";
        if (s.equals("Sunny")) {
            result = "Cloudy";
        } else if (s.equals("Rainy")) {
            result = "Sunny";
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 35528
#include<stdio.h>
int main()
{
    int n,m,x,y;
    int flag;
    int ans;
    int a[105],b[105];
	scanf("%d %d %d %d",&n,&m,&x,&y);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&b[i]);
	}
	for(int i=x+1;i<=y;i++)
	{
		flag=0,ans=0;
       for(int j=1;j<=n;j++)
	   {
	   	if(i>a[j])
	    flag++;
	    else
		break;	
	   }
	   for(int k=1;k<=m;k++)
	   {
	   	if(i<=b[k])
	   	ans++;
	   	else
	   	break;
	   }
		if(flag==n&&ans==m)
		break; 
	} 
	if(flag==n&&ans==m)
	printf("No War");
	else
	printf("War");
	return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
}


Measured memory_bytes: 256
//package abc120_B;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		
		int cnt = 0;
		for (int i = 100; i > 0; i--) {
			if (a % i == 0 && b % i == 0) cnt++;
			if (cnt == k) {
				System.out.println(i);
				return;
			}
		}
	}

}

Measured memory_bytes: 21972
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>

//AtCoderC++.cpp

using namespace std;

template<typename T> void Show(const vector<vector<T>>& v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j];
			if (j != v[i].size() - 1) {
				cout << delimiter;
			} else {
				cout << endl;
			}
		}
	}
}
template<typename T> void Show(const vector<T>& v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i != v.size() - 1) {
			cout << delimiter;
		} else {
			cout << endl;
		}
	}
}
template<typename T> vector<T> getUniform(T value, int n) {
	vector<vector<T>> ts;
	ts.resize(n);
	for (int i = 0; i < n; i++) {
		ts[i] = value;
	}
	return ts;
}
template<typename T> vector<vector<T>> getUniform(T value, int row, int col) {
	vector<vector<T>> ts;
	ts.resize(row);
	for (int i = 0; i < row; i++) {
		ts[i].resize(col);
		for (int j = 0; j < col; j++) {
			ts[i][j] = value;
		}
	}
	return ts;
}
bool All(vector<vector<bool>> ts) {
	int h = ts.size();
	int w = ts[0].size();
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if (!ts[i][j])return false;
	return true;
}


vector<string> split(string& content, char delim) {
	auto ss = vector<string>();
	string s = "";
	for (size_t i = 0; i < content.length(); i++) {
		if (content[i] == delim) {
			ss.push_back(s);
			s = "";
			continue;
		}
		s += content[i];
	}
	if (s != "")ss.push_back(s);
	return ss;
}

//mapで書き換えるか。値と個数のペアだ。
//それか大きい順に適用してみよう

struct my_pair {
	int b, c;
	bool operator<(my_pair p) {
		return c < p.c;
	}
};
int main() {
	int A, P;
	cin >> A >> P;
	cout << (A * 3 + P) / 2 << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		/*
		Scanner sc = new Scanner(System.in);
		int i = Integer.parseInt(sc.next());
		
		System.out.println(i);
		*/
		
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		
		int count = 0;
		
		for(int i = 0 ; i < 3 ; i++) {
			if (S.charAt(i) == T.charAt(i)) {
				count++;
			}
		}
		
		System.out.print(count);
		
	}

}


Measured memory_bytes: 21332
n = int(input())
r_l = []

for id_ in range(n):
    c_s = input().split()
    r_l.append((id_ + 1, c_s[0], 100-int(c_s[1])))

r_l = sorted(r_l, key = lambda x: (x[1], x[2]))

for l in r_l:
    print(l[0])

Measured memory_bytes: 3060
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define y0 u9cqu3jioajc

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

const int MN = 100111;
int n, a[MN], f[MN];
vector<int> ke[MN];

void dfs(int u, int fu) {
    int sum = 0;
    int ln = -1;
    bool hasChild = 0;

    for(int v : ke[u]) {
        if (v == fu) continue;

        dfs(v, u);
        hasChild = 1;
        sum += f[v];
        ln = max(ln, f[v]);
    }

    if (!hasChild) {
        f[u] = a[u];
        return ;
    }

    int pair = sum - a[u];
    f[u] = a[u] - pair;

    if (pair < 0) throw 1;
    if (f[u] < 0) throw 1;

    if (pair > sum - ln) throw 1;

}

bool solve() {
    if (n == 2) return a[1] == a[2];

    int root = -1;
    FOR(i,1,n) if (SZ(ke[i]) > 1) {
        root = i;
        break;
    }
    assert(root > 0);

    try {
        dfs(root, -1);
        return f[root] == 0;
    } catch (...) {
        return false;
    }
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9);
    while (GI(n) == 1) {
        FOR(i,1,n) GI(a[i]);
        FOR(i,1,n) ke[i].clear();

        FOR(i,2,n) {
            int u, v; GI(u); GI(v);
            ke[u].push_back(v);
            ke[v].push_back(u);
        }

        cout << (solve() ? "YES" : "NO") << endl;
    }
}


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

// mod の処理を忘れさせてくれるライブラリ
// https://github.com/atcoder-live/library/blob/master/mint.cpp
const int mod = 1000000007;
struct mint {
  long long x;
  mint(long long x = 0):x((x % mod + mod) % mod) {}
  mint operator-() const {return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

// 繰り返し自乗法で m の n 乗を計算する
mint f (int m, int n) {
  mint result = 1;
  if (0 < n) {
    result = f(m, n / 2);
    if (n % 2 == 0) {
      result *= result;
    } else {
      result *= result;
      result *= m;
    }
  }
  return result;
}

int main() {

  long long m, n;
  cin >> m >> n;

  mint answer = f(m, n);

  cout << answer.x << endl;

  return 0;

}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int n;
	cin >> n;
	cout << (n+1)/2*(n/2) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100

int main(void){
  int i,N,a[MAX],min=1000,max=0;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
    if(min>a[i])
    min=a[i];
    if(max<a[i])
    max=a[i];
  }
  printf("%d\n",max-min);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

typedef long long ll;
const ll INFTY = (ll(1) << 60);

int main()
{
    ll H, W, m1, m2, m3, num, max_m, min_m, ans=INFTY;
    cin >> H >> W;
    
    for(int i=1;i<H;++i){
        m1 = W*i;
        // (H - i) * W;
        num = W / 2;
        m2 = (H - i) * num;
        m3 = (H - i) * (W - num);
        max_m = max(max(m1, m2), m3);
        min_m = min(min(m1, m2), m3);
        ans = ans > (max_m - min_m) ? max_m - min_m : ans;
        num = (H - i) / 2;
        m2 = num * W;
        m3 = (H - i - num) * W;
        max_m = max(max(m1, m2), m3);
        min_m = min(min(m1, m2), m3);
        ans = ans > (max_m - min_m) ? max_m - min_m : ans;
    }

    for(int i=1;i<W;++i){
        m1 = H*i;
        // (H - i) * W;
        num = H / 2;
        m2 = (W - i) * num;
        m3 = (W - i) * (H - num);
        max_m = max(max(m1, m2), m3);
        min_m = min(min(m1, m2), m3);
        ans = ans > (max_m - min_m) ? max_m - min_m : ans;
        num = (W - i) / 2;
        m2 = num * H;
        m3 = (W - i - num) * H;
        max_m = max(max(m1, m2), m3);
        min_m = min(min(m1, m2), m3);
        ans = ans > (max_m - min_m) ? max_m - min_m : ans;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
//
// Created by watemus on 10.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

#ifdef LOCAL
#else
#endif


void run() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = min(a, k);
    k -= a + b;
    if (k > 0) {
        ans -= k;
    }
    cout << ans << '\n';
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

Measured memory_bytes: 3640
# include <iostream>
# include <algorithm>
# include <cmath>
# include <tuple>
# include <vector>
# include <queue>
# include <string>

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    priority_queue<ll> q;
    int n, m; cin >> n >> m;
    for (int i = 0; i < n; i++) {
        ll a; cin >> a;
        q.push(a);
    }
    for (int i = 0; i < m; i++) {
        ll v = q.top();
        q.pop();
        q.push(v/2);
    }
    ll ans = 0;
    while (!q.empty()) {
        ll v = q.top();
        q.pop();
        ans += v;
    }
    cout << ans << endl;
    return 0;
}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	// cin>>t;
	t = 1;
	while(t--){
		int n;
		cin>>n;
		int arr[n];
		int dp[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
			dp[i] = INT_MAX;
		}
		dp[0]=0;
		for(int i=1;i<n;i++){
			for(int j=i-2; j<i;j++){
				if(j>=0){
					dp[i] = min(dp[i],dp[j] + abs(arr[i] - arr[j]));
				}
			}
		}
		cout<<dp[n-1]<<'\n';
	}
}

Measured memory_bytes: 1024
#include <iostream>
    #include <string>
    #include <algorithm>
    using namespace std;
     
    int main() {
        string S, T;
        cin >> S >> T;
     
        //Initialize ans with a temporal value.
        //This value should be large enough; otherwise you will get wrong answer
        //Make sure that the value will lead to the correct answer.
        int ans = T.size();
     
        //Brute force through all initial position in S
        for (int start = 0; start <= S.size() - T.size(); start++)
        {
            int diff = 0;
            for (int i = 0; i < T.size(); i++)
            {
                if (T[i] != S[start + i]) {
                    diff++;
                }
            }
            ans = min(ans, diff);
        }
     
        cout << ans << endl;
    }

Measured memory_bytes: 3596
# ABC 126 B - YYMM or MMYY
S = input()
a = 0
b = 0

v = str(S[:2])
u = str(S[2:])
month = ['01', '02', '03', '04', '05', '06', '07','08','09','10','11','12']
if u in month:
    a = 1
if v in month:
    b = 1
if a == 1 and b == 1:
    print('AMBIGUOUS')
if a == 1 and b == 0:
    print('YYMM')
if a == 0 and b == 1:
    print('MMYY')
if a ==0 and b == 0:
    print('NA')


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<int> w(n),e(n);

    if(s[0] == 'W') w[0] = 1;
    else e[0] = 1;
    
    for(int i=1;i<n;i++){
        if(s[i] == 'W'){
            w[i] = w[i-1] + 1; 
            e[i] = e[i-1];
        }else{
            e[i] = e[i-1] + 1;
            w[i] = w[i-1];
        }
    }
    int ans = 1e6;
    rep(i,n){
        int a = w[i-1]; 
        int b = e[n-1] - e[i];
        ans = min(ans,a+b);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        double h = s.nextInt(),a = s.nextInt();
        System.out.println((int)(Math.ceil(h/a)));

    }
}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

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

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

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  string S;
  cin >> S;
  cout << (S=="ABC" ? "ARC" : "ABC") << endl;
  return 0;
}


Measured memory_bytes: 3592
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

LL BIG = INFF * 8;
unordered_map<LL, LL> dp;
LL a,b,c,d,n;
LL cost[6];
int T;

LL f(LL n)
{
  if (n == 0) return 0;
  if (dp.count(n)) return dp[n];
  LL res = BIG;
  if (n <= BIG / d) MIN(res,n*d);
  for (int x : {2, 3, 5})
  {
    MIN(res,(n % x) * d + cost[x] + f(n/x));
    if (n % x != 0 && n > x) MIN(res,(x - n % x) * d + cost[x] + f(n/x + 1));
  }
  return dp[n] = res;
}

int main()
{
  scanf("%d",&T);
  TC(T)
  {
    scanf("%lld %lld %lld %lld %lld",&n,&cost[2],&cost[3],&cost[5],&d);
    dp.clear();
    printf("%lld\n",f(n));
  }
  return 0;
}











Measured memory_bytes: 4276
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;

int main(void) {
    string str;
    cin >> str;
    int str_len = (int)str.length();
    bool num = false;
    bool big = false;
    bool small = false;
    bool len = false;

    if (str_len >= 6) {
        len = true;
    }

    for (int i = 0; i < str_len; i++) {
        if (num == false && str[i] >= '0' && str[i] <= '9') {
            num = true;
        } else if (big == false && str[i] >= 'a' && str[i] <= 'z') {
            big = true;
        } else if (small == false && str[i] >= 'A' && str[i] <= 'Z') {
            small = true;
        }
    }

    if (num && big && small && len) {
        cout << "VALID" << endl;
    } else {
        cout << "INVALID" << endl;
    }
    return 0;
}

Measured memory_bytes: 3204
program ABC_092_B_Chocolate
   implicit none
   integer(8) N, D, X, total, i, j, k
   integer(8), allocatable :: A(:), countA(:), dayAk(:, :) 
   read(*, *) N
   read(*, *) D, X
   allocate (A(1:N))
   allocate (countA(1:N))
   allocate (dayAk(1:N,1:D))
   do i = 1, N
      read(*, *) A(i)
   end do
   countA(:) = 0
   do k = 1, N
      do j = 1, D
	     dayAk(k, j) = (j - 1) * A(k) + 1
         if(dayAk(k, j) <= D) then
	          countA(k) = countA(k) + 1
	     end if
      end do
   end do
   total = 0
   total = sum(countA) + X
   write(*, *)total
end program ABC_092_B_Chocolate

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int x;
	scanf("%d", &x);
	
	if(x >= 400 && x <= 599)
		printf("8");
	if(x >= 600 && x <= 799)
		printf("7");
	if(x >= 800 && x <= 999)
		printf("6");
	if(x >= 1000 && x <= 1199)
		printf("5");
	if(x >= 1200 && x <= 1399)
		printf("4");
	if(x >= 1400 && x <= 1599)
		printf("3");
	if(x >= 1600 && x <= 1799)
		printf("2");
	if(x >= 1800 && x <= 1999)
		printf("1");
	return (0);
}


Measured memory_bytes: 2092
s=str(input())
sl=len(s)+1
l,r=[0]*sl,[0]*sl
ss=[0]*sl
lcnt,rcnt=0,0
for i in range(sl):
  if i==0:
    l[0]=0
    r[sl-1]=0
  else:
    if s[i-1]=="<":
      lcnt+=1
    else:
      lcnt=0
    if s[sl-i-1]==">":
      rcnt+=1
    else:
      rcnt=0
    l[i]=lcnt
    r[sl-i-1]=rcnt
for i in range(sl):
  ss[i]=max(l[i],r[i])
print(sum(ss))

Measured memory_bytes: 31180
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

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

  vector<int> h;
  int t;
  for(int i=0;i<n;i++){
    cin>>t;
    h.pb(t);
  }
  sort(h.begin(),h.end());
  t=h[n-1]-h[0];
  
  for(int i=0;i<=n-k;i++){
    t=min(t,h[i+k-1]-h[i]);
  }
  cout<<t<<endl;
  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
int main(){
    int x,y,z,k; cin >> x >> y >> z >> k;
    vector<ll> a(x);
    rep(i,x) cin >> a[i];
    vector<ll> b(y);
    rep(i,y) cin >> b[i];
    vector<ll> c(z);
    rep(i,z) cin >> c[i];
    vector<ll> ab(1000005);
    rep(i,x){
        rep(j,y){
            ll sum = (ll)(a[i] + b[j]);
            ab.push_back(sum);
        }
    }
    sort(ab.rbegin(), ab.rend());
    sort(c.rbegin(), c.rend());
    vector<ll> ans(9000005);
    int p = min(x*y,k);
    rep(i,p){
        rep(j,z){
            ll sum2 = (ll)(ab[i] + c[j]);
            ans.push_back(sum2);
        }
    }
    sort(ans.rbegin(), ans.rend());
    rep(i,k) cout << ans[i] << endl;
}


Measured memory_bytes: 158584
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;

static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}


class Program
{
    static void Main()
    {
        var abq = Console.ReadLine().ToIntArray();

        int A = abq[0];
        int B = abq[1];
        int Q = abq[2];

        var sList = Enumerable.Range(0, A).Select(n => Console.ReadLine().ToLong()).OrderBy(n => n).ToList();
        var tList = Enumerable.Range(0, B).Select(n => Console.ReadLine().ToLong()).OrderBy(n => n).ToList();
        var xList = Enumerable.Range(0, Q).Select(n => Console.ReadLine().ToLong()).ToList();

        
        foreach (var x in xList)
        {
            var tmpSList = new List<int>();
            var tmpTList = new List<int>();
            //すぐ右にあるsは
            var sIdx = sList.BinarySearch(x);
            if (sIdx < 0) sIdx ^= -1;
            if (sIdx <= sList.Count - 1)
            {
                tmpSList.Add(sIdx);
            }
            //すぐ左にあるsは
            if (sIdx - 1 >= 0)
            {
                tmpSList.Add(sIdx - 1);
            }

            //すぐ右にあるtは
            var tIdx = tList.BinarySearch(x);
            if (tIdx < 0) tIdx ^= -1;
            if (tIdx <= tList.Count - 1)
            {
                tmpTList.Add(tIdx);
            }
            //すぐ左にあるtは
            if (tIdx - 1 >= 0)
            {
                tmpTList.Add(tIdx - 1);
            }

            long ans = 100000000000;
            foreach(var t in tmpTList)
            {
                foreach(var s in tmpSList)
                {
                    ans = Math.Min(ans, Math.Abs(x - tList[t]) + Math.Abs(sList[s] - tList[t]));
                    ans = Math.Min(ans, Math.Abs(x - sList[s]) + Math.Abs(sList[s] - tList[t]));
                }
            }

            Console.WriteLine(ans);
        }
    }
}

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

int N, M;

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

    cin >> N >> M;
    int success = 1;  // 成功確率の逆数
    for (int i = 0; i < M; i++) {
        success *= 2;
    }
    cout << ((N - M) * 100 + M * 1900) * success << endl;
}

Measured memory_bytes: 256