akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <climits>
#include <cassert>

using namespace std;
typedef unsigned int index;

class Exec
{
private:
	long long n, m;

public:
	Exec(){}

	void main()
	{
		long long t = m * 1900 + (n - m) * 100;
		cout << t * (1 << m) << endl;
	}

	void read()
	{
		cin >> n >> m;
	}

};

int main()
{
#ifdef ONPC
	assert(freopen("a.in", "r", stdin));
	assert(freopen("a.out", "w", stdout));
#else
#endif
	Exec a;
	a.read();
	a.main();
}


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

using namespace std;

#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main(void){
    int x;
    cin >> x;

    cout << x * 360 / __gcd(x, 360) / x << "\n";

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

ll rec(ll n) {
    if(n <= 11) return n+1;
    if(n%10!=9 && (n/10)%10 >= n%10) return n+1;
    ll f = rec(n/10);
    ll t = max(0ll, f%10 - 1);
    return f*10 + t;
}

int main() {
    int K; cin >> K;
    ll n = 0;
    rep(i,K) {
        n = rec(n);
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int i=0;
    while(1){
        if(i==0){
            c-=b;
            if(c<=0){
                cout<<"Yes"<<"\n";
                return 0;
            }
        }else{
            a-=d;
            if(a<=0){
                cout<<"No"<<"\n";
                return 0;
            }
        }
        i^=1;
    }
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>

typedef char String[1024];

int main(void)
{
    String inw, inh, inx, iny, inr;
    scanf("%s %s %s %s %s", inw, inh, inx, iny, inr);
    
    int w = atoi(inw);
    int h = atoi(inh);
    int x = atoi(inx);
    int y = atoi(iny);
    int r = atoi(inr);
    
    if (x > 0 && x < w)
    {
        if (y > 0 && y < h)
        {
            if (((x + r) <= w && (x - r) >=  0) && ((y + r) <= h && (y - r) >= 0))
                printf("Yes\n");
            else
                printf("No\n");
        }
        else
            printf("No\n");
    }
    else
        printf("No\n");
    return (0);
}


Measured memory_bytes: 2084
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int MAX_N = 200010;

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

    vector<int> c(MAX_N);
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
    }

    vector<ll> dp(MAX_N);  // dp[i] : 最初からi個(iは1-index)の石の場合の数
    vector<int> v(MAX_N);  // v[i] : j < i かつ c[j] = c[i] となる最大のj (存在しないときは0)
    vector<int> w(MAX_N);  // vを埋めるための補助的なvector

    for(int i = 1; i <= n; i++) {
        v[i] = w[c[i]];
        w[c[i]] = i;
    }

    dp[0] = 1;
    for(int i = 1; i <= n; i++) {
        dp[i] = dp[i-1];  // i個目の石に操作をしない場合の数はdp[i-1]通り
        if(v[i] != 0 && v[i] != i-1) {  // j < i かつ c[j] = c[i] となるjが存在して、c[i-1] != c[i] のとき
            dp[i] += dp[v[i]];  // i個目とv[i]個目の石に対して操作を行うときの場合の数はdp[v[i]]通り
            dp[i] %= mod;
        }
    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

int N;
cin>>N;
vector<long long> A(N);
rep(i,N)cin>>A[i];

sort(A.begin(),A.end());
long long ans=1;
long long s[N+1];

s[0]=0;

rep(i,N){
    s[i+1]=s[i]+A[i];
}
bool bacome=true;

for(int i=N-1;i>-1;i--){

    if(s[i]*2>=A[i])ans++;
    else    break;
}

cout<<ans<<endl;

 return 0;
}
/*
3
3 1 4

2


5
1 1 1 1 1

5

6
40 1 30 2 7 20

4
*/

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N;
    cin >> N;

    int root = sqrt(N);

    for (int i = root; i >= 1; i--) {
        int tmp = N / i;
        if (i * tmp == N) {
            cout << i + tmp - 2 << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
//using namespace boost::multiprecision;  
//using namespace boost::math;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
//inline int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
//inline int lcm(int a,int b){ return a / gcd(a,b) * b;}
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
//}}}
int n;
vector<string> res;

string dfs(int k,string s,char maxc){
    if(k == n) return s;
    res.emplace_back(dfs(k+1,s,maxc));
    while(s[k] <= maxc + 1){
        res.emplace_back(dfs(k+1,s,max(maxc,s[k])));
        if(s[k] == maxc + 1) break;
        s[k]++;
    }
    return s;
}



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

    cin >> n;
    string s(n,'a');
    if(n == 1){
        return cout << 'a' << '\n',0;
    }

    dfs(1,s,'a');

    sort(all(res));
    res.erase(unique(all(res)),res.end());

    for(auto e : res){
        cout << e << '\n';
    }

    return 0;
}



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

typedef long long ll;

using namespace std;

const ll MOD = 998244353;

#define all(x) (x).begin(), (x).end()
#define int long long

map<string, int> dp;

ll solve(string s)
{
    if (s == "") return 1;
    if (dp.find(s) != dp.end()) return dp[s];
    ll ans = 0;
    string t = "";
    for (int i = 1; i < s.size(); i++) t += s[i];
    if (s[0] == '1') ans = 2 * solve(t);
    else ans = solve(t);
    if (ans >= MOD) ans -= MOD;
    for (int k = 2; k <= s.size(); k++)
    {
        for (int len = 1; len * k <= s.size(); len++)
        {
            string t = "";
            for (int j = len * k; j < s.size(); j++) t += s[j];
            string p = "";
            for (int i = 0; i < len; i++) p += s[i];
            for (int j = 1; j < k; j++) for (int i = 0; i < len; i++)
                p[i] = min(p[i], s[j * len + i]);
            ans = (ans + solve(t) * solve(p)) % MOD;
        }
    }
    return dp[s] = ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    cout << solve(s);
}


Measured memory_bytes: 6400
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int Maxn = 2000;
const int INF = 0x3f3f3f3f;

int N;
char s[Maxn + 5];

vector<int> G[Maxn + 5];
int siz[Maxn + 5];
int mn[Maxn + 5], mx[Maxn + 5];

void DFS(int u, int fa) {
	siz[u] = mn[u] = mx[u] = 0;
	for(int i = 0; i < (int)G[u].size(); i++) {
		int v = G[u][i];
		if(v == fa) continue;
		DFS(v, u);
		mx[v] += siz[v], mn[v] += siz[v], siz[u] += siz[v];
		if(max(mn[u], mn[v]) <= min(mx[u], mx[v]))
			mn[u] = ((mn[u] & 1) ^ (mn[v] & 1));
		else mn[u] = max(mn[u], mn[v]) - min(mx[u], mx[v]);
		mx[u] += mx[v];
	}
	if(s[u] == '1') siz[u]++;
}

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d %s", &N, s + 1);
	for(int i = 1; i < N; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		G[u].push_back(v), G[v].push_back(u);
	}
	int ans = INF;
	for(int i = 1; i <= N; i++) {
		DFS(i, 0);
		if(!mn[i])ans = min(ans, mx[i] / 2);
	}
	printf("%d\n", ans == INF ? -1 : ans);
	return 0;
}

Measured memory_bytes: 512
#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];
  }
  map<int, int> mp;
  for (int i = 0; i < N; i++){
    mp[a[i]]++;
  }
  if (mp.size() == 1){
    if ((*(mp.begin())).first == 0){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else if (mp.size() == 2){
    if (N % 3 != 0){
      cout << "No" << endl;
    } else {
      bool ok = false;
      for (auto P : mp){
        if (P.second * 3 == N){
          ok = true;
        }
      }
      if (ok){
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  } else if (mp.size() == 3){
    if (N % 3 != 0){
      cout << "No" << endl;
    } else {
      int cnt = 0; 
      for (auto P : mp){
        if (P.second * 3 == N){
          cnt++;
        }
      }
      if (cnt != 3){
        cout << "No" << endl;
      } else {
        vector<int> B;
        for (auto P : mp){
          B.push_back(P.first);
        }
        if ((B[0] ^ B[1]) != B[2]){
          cout << "No" << endl;
        } else {
          cout << "Yes" << endl;
        }
      }
    }
  } else {
    cout << "No" << endl;
  }
}

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

const int base = 510;
const int mod = 1e9 + 7;

int n;
string s;
map<pair<int,int>,int> mp;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> s;
	reverse(s.begin() + n, s.begin() + n + n);
	for (int i = 0; i < (1 << n); ++i) {
		int hsA = 0, hsB = 0;
		for (int j = 0; j < n; ++j) {
			if ((i >> j) & 1) hsA = (1ll * hsA * base % mod + (s[j] - 'a' + 1)) % mod;
			else hsB = (1ll * hsB * base % mod + (s[j] - 'a' + 1)) % mod;
		}
		mp[{hsA, hsB}]++;
	}
	long long ans = 0;
	for (int i = 0; i < (1 << n); ++i) {
		int hsA = 0, hsB = 0;
		for (int j = 0; j < n; ++j) {
			if ((i >> j) & 1) hsA = (1ll * hsA * base % mod + (s[j + n] - 'a' + 1)) % mod;
			else hsB = (1ll * hsB * base % mod + (s[j + n] - 'a' + 1)) % mod;
		}
		ans += mp[{hsA, hsB}];
	}
	cout << ans << '\n';
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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; }

void add(ll& a, ll b){a = (a+b) % MOD;}

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<ll> A(n);
    ll minus=0,mi=INF+7;
    REP(i,n){
        cin>>A[i];
        if(A[i]<0) minus++;
        mi = min(mi,abs(A[i]));
    }

    ll ans=0;
    if(minus%2==0){
        REP(i,n){
            ans += abs(A[i]);
        }
    }
    else{
        REP(i,n){
            if(mi==abs(A[i])) ans-=abs(A[i]);
            else ans+=abs(A[i]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int H, W, c, a[9][9], b[9][9], g[6][9][9], v[9][9];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int rec1(int x, int y) {
	int ret = 1; v[y][x] = 1;
	for (int i = 0; i < 4; i++) {
		int tx = x + dx[i], ty = y + dy[i];
		if (0 <= tx && tx < W && 0 <= ty && ty < H && b[y][x] == b[ty][tx] && !v[ty][tx]) ret += rec1(tx, ty);
	}
	return ret;
}
void rec(int x, int y, int e) {
	int w = b[y][x]; b[y][x] = e;
	for (int i = 0; i < 4; i++) {
		int tx = x + dx[i], ty = y + dy[i];
		if (0 <= tx && tx < W && 0 <= ty && ty < H && b[ty][tx] == w) rec(tx, ty, e);
	}
}
void cpy(int d, int m) {
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			switch (m) {
			case 0: g[d][i][j] = b[i][j]; break;
			case 1: b[i][j] = g[d][i][j]; break;
			case 2: v[i][j] = 0; break;
			}
		}
	}
}
int solve(int d) {
	int ret = 0; cpy(d, 0);
	if (b[0][0] != c) rec(0, 0, c);
	cpy(0, 2), ret = rec1(0, 0), cpy(d, 1);
	if (d < 4) {
		for (int i = 1; i <= 6; i++) {
			if (b[0][0] == i) continue;
			cpy(d, 0), rec(0, 0, i);
			ret = max(ret, solve(d + 1)), cpy(d, 1);
		}
	}
	return ret;
}
int main() {
	while (scanf("%d%d%d", &H, &W, &c), H) {
		memset(g, 0, sizeof(g));
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) scanf("%d", &a[i][j]), b[i][j] = a[i][j];
		}
		printf("%d\n", solve(0));
	}
	return 0;
}

Measured memory_bytes: 2728
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,l;
	cin >> n;
	vector<ll> a(n);
	cin >> a[0];
	for(ll i = 1; i < n; i++) {
		cin >> l;
		a[i] = a[i - 1] + l;
	}
	ll tmp = 0;
	ll count = 0;
	//奇数番目が正のとき

	if (a[0] <= 0){
		count += abs(a[0])+1;
		tmp += abs(a[0]) + 1;
	}
	for(int i = 1; i < n; i++) {
		if(i % 2 == 1 && a[i]+tmp >= 0){//偶数番目が0より大きい時
			count += abs(a[i] + tmp)+1;
			tmp -=(abs(a[i] + tmp) + 1);
		}
		else if(i % 2 == 0 && a[i]+tmp <= 0){//奇数番目が負の時
			count += abs(a[i] + tmp)+1;
			tmp +=(abs(a[i] + tmp) + 1);
		}
	}
	ll ans1 = count;
	count = 0;
	tmp = 0;

	//遇数番目が正のとき
	if (a[0] >= 0){
		count += abs(a[0])+1;
		tmp -= abs(a[0]) + 1;
	}
	// cout << a[0] +tmp << endl;
	for(int i = 1; i < n; i++) {
		if(i % 2 == 1 && a[i]+tmp <= 0){//偶数番目が0より小さい時
			count += abs(a[i] + tmp)+1;
			tmp +=(abs(a[i] + tmp) + 1);
		}
		else if(i % 2 == 0 && a[i]+tmp >=0){//奇数番目が正の時
			count += abs(a[i] + tmp)+1;
			tmp -=(abs(a[i] + tmp) + 1);
		}
		// cout << a[i] + tmp << endl;

	}
	cout << min(ans1,count) <<endl;
	return 0;
}

Measured memory_bytes: 1024
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e2+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

ll w[maxn], v[maxn];
ll dp[maxn][100005];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int n, W;
    scanf("%d%d", &n, &W);

    ll answer = 0;
    for(int i = 1; i <= n; i++) scanf("%lld%lld", &w[i], &v[i]);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= W; j++)
        {
            if(j >= w[i])   dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
            else            dp[i][j] = dp[i - 1][j];
            answer = max(answer, dp[i][j]);
        }
    }
    printf("%lld\n", answer);


    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,j,k,coun=0;
    cin>>n;
    long long int arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            for(k=j+1;k<n;k++)
            if((arr[i]!=arr[j])&&(arr[j]!=arr[k])&&(arr[i]!=arr[k]))
                if((arr[i]+arr[j]>arr[k])&&(arr[i] + arr[k] > arr[j])&&(arr[k] + arr[j] > arr[i]))
                      coun++;
        }
    }
    cout<<coun<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

ll dp[101010][111][2];

int main(){
  string K; cin>>K;
  int D; cin>>D;
  reverse(K.begin(),K.end());
  dp[K.length()][0][0]=1;
  for(int i=K.length()-1;i>=0;i--) rep(j,D){
    int num=K[i]-'0';
    rep(k,10){
      (dp[i][(j+k)%D][1]+=dp[i+1][j][1])%=MOD;
      if(k<num) (dp[i][(j+k)%D][1]+=dp[i+1][j][0])%=MOD;
      if(k==num) (dp[i][(j+k)%D][0]+=dp[i+1][j][0])%=MOD;
    }
  }
  cout<<(dp[0][0][0]+dp[0][0][1]-1+MOD)%MOD<<endl;
  return 0;
}


Measured memory_bytes: 18688
#include <bits/stdc++.h>
#define L "\n"
#define S " "
#define ll long long
#define pb push_back
#define mp make_pair
#define vi std::vector<int>
#define si std::set<int>
#define vl std::vector<long long>
#define qi std::queue<int>
#define de(a) cout << #a << "  ------>  " << a << "\n"
#define SIZE 3001
#define INF INT_MAX
#define FOR(i, n) for (i = 1; i <= n; i++)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;

int a[SIZE];
ll dp[SIZE][SIZE][2];
bool flag[SIZE][SIZE][2];


ll f(int i, int j, int p)
{
    ll d1, d2;
    if(i == j){
        if(p == 1)  return dp[i][j][1] = a[i];
        else return dp[i][j][0] = -a[i];
    }
    flag[i][j][p] = 1;
    if (p == 1)
    {
        if(flag[i + 1][j][0]) d1 = dp[i + 1][j][0];
        else d1 = f(i + 1, j, 0);
        if(flag[i][j - 1][0]) d2 = dp[i][j - 1][0];
        else d2 = f(i, j - 1, 0);

        return dp[i][j][p] = max(d1 + a[i], d2 + a[j]);
    }
    else
    {
        if(flag[i + 1][j][1]) d1 = dp[i + 1][j][1];
        else d1 = f(i + 1, j, 1);
        if(flag[i][j - 1][1]) d2 = dp[i][j - 1][1];
        else d2 = f(i, j - 1, 1);

        return dp[i][j][p] = min(d1 - a[i], d2 - a[j]);
    }
}

void solve()
{
    int n, i;
    cin >> n;
    FOR(i, n)
    cin >> a[i];
    cout << f(1, n, 1) << L;
}
int main()
{
    FASTIO;
    // #ifndef ONLINE_JUDGE
    //     freopen("in.txt", "r", stdin);
    // #endif
    int t;
    // cin >> t;
    // while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 158208
n = int(input())
h = [int(i) for i in input().split()]

def mincostdp(n):
    #iがkey, iに到達する最小コストがvalue
    mincostdc = dict()
    mincostdc[0], mincostdc[1] = 0, abs(h[1]-h[0])

    for i in range(2, n):
        mincostdc[i] = min((mincostdc[i-1]+abs(h[i]-h[i-1])), (mincostdc[i-2]+abs(h[i]-h[i-2])))
    return mincostdc[n-1]

print(mincostdp(n))

Measured memory_bytes: 23236
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int i,n,j,x,y,p[100000];
  char str[10];
  
  fgets(str,sizeof(str),stdin);
  x=atoi(str);
  
  n=-1;
  while(n<0){
    y=(int)sqrt((double)x);
    for(i=2;i<=x;i++){
      if(x%i==0&&x!=i){
        break;
      }
      if(i==x){
        n=x;
      }
    }
    x++;
  }
  
  printf("%d\n",n);
  return 0;
}

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

int main(){
	int n,a,b,cnt=0,bnt=1;
  string s,ans = "No";
  cin  >> n >> a >> b >>s;
  vector<int>k;
  for(int i = 0;i < n;i++){
    ans = "No";
    if(s[i] == 'a'){
    	if((a + b) > cnt){
        	cnt++;
          	ans = "Yes";
        }
    }
    if(s[i] == 'b'){
    	if((a + b) > cnt && bnt <= b){
        	bnt++;
          	cnt++;
          	ans = "Yes";
        }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#include<time.h>
#define pi acos(-1.0)
using namespace std;
int main()
{
//	long long begin_time=clock();
//	int t;
//	scanf("%d",&t);
///	while(t--)
//	{
	//	int n,i,j,flag=0,x=0,y=0,ma=0,mi=0x3f3f3f3f;
	//	char s[];
	//	int a[],b[];
	    int a,b,c,d;
	    double k,x,y,z;
	    scanf("%d%d%d%d",&a,&b,&c,&d);
	    c%=12;
	    d%=60;
	    x=c*30+d/2.0;
	    y=d*360/60;
	    //printf("%lf %lf ",x,y);
	    z=x-y;
	    if(z>180)
	    z=360-(x-y);
	    //printf("%lf ",z);
	    k=pow(a*a+b*b-2*a*b*cos(z*pi/180),0.5);
	    printf("%.9lf\n",k);
//	}
//	long long end_time=clock();
//	printf("time=%lldms\n",end_time-begin_time);
}


Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=202;

char adjM[N][N];

int res_BFS(int v,int n);

int main()
{
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%s",adjM[i]+1);
	int res = -1;
	for(int i=1;i<=n;i++) res = max(res,res_BFS(i,n));
	printf("%d\n",res);
}
///////
int res_BFS(int v,int n)
{
	queue<int> kol;
	int dist[N];
	for(int i=1;i<=n;i++) dist[i]=2*N;
	kol.push(v);
	dist[v]=0;

	while(!kol.empty())
	{
		int x = kol.front();
		kol.pop();

		for(int i=1;i<=n;i++)
		{
			if(adjM[x][i]=='1' && dist[i]>dist[x]+1)
			{
				dist[i]=dist[x]+1;
				kol.push(i);
			}
		}
	}

	int res = 0;
	for(int i=1;i<=n;i++)
	{
		res = max(res,dist[i]);
		for(int j=1;j<=n;j++)
		{
			if((dist[i]==dist[j] || abs(dist[i]-dist[j])>1) && adjM[i][j] == '1') return -1;
		}
	}

	return res+1;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back
#define INF (1e9+1)

string s;

int hf(int &p, string &id){
    if('a'<=s[p] && s[p]<='d'){
        int ret = id[s[p]-'a']-'0';
        p++;
        return ret;

    }else{
        assert('[');
        p++;
        char op = s[p];
        p++;
        int left = hf(p,id);
        int right = hf(p,id);
        assert(']');
        p++;

        if(op=='*')return left & right;
        if(op=='+')return left | right;
        if(op=='^')return left ^ right;
    }
    abort();
    return -1;
}

int main(){
    while(cin>>s&&s!="."){
        string id;
        cin>>id;

        int num = 0;
        int res = hf(num,id);

        int sum = 0;
        rep(i,10000){
            stringstream ss;
            ss<<i;
            string t = ss.str();
            while(t.size()<4)t = "0"+t;
            int num = 0;
            if(res==hf(num,t))sum++;
        }
        cout<<res<<" "<<sum<<endl;
    }
}



Measured memory_bytes: 3204
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    println!("{}", a * b);
}


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

const int SIZE = 1e6;
int A[SIZE], B[SIZE];

int main() {
	int M, N, C, D; cin >> M >> N >> C >> D;
	for(int pos = 1; pos <= M; pos++)
		cin >> A[pos];
	for(int pos = 1; pos <= N; pos++)
		cin >> B[pos];
	sort(A + 1, A + 1 + M);
	sort(B + 1, B + 1 + N);
	if(B[1] <= A[M]) {
		cout << "War" << endl; return 0;
	}
	if((A[M] > C && A[M] < D) || (B[1]) > C && B[1] < D)
		cout << "No War" << endl;
	else 
		cout << "War" << endl;
}


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

int main() {
	int a, b;
	char op;
	while(1) {
		cin >> a >> op >> b;
		if (op == '?') {
			break;
		}else if (op == '+') {
			cout << a + b <<endl;
		}else if (op == '-') {
			cout << a - b <<endl;
		}else if (op == '*') {
			cout << a * b <<endl;
		}else if (op =='/') {
			cout << a / b <<endl;
		}
	}
		
}


Measured memory_bytes: 3088
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
a = [int(i) for i in input().split()]

box = [0] * N

for i in range(N-1, -1, -1):
    # (i+1)の倍数が書かれた箱を探索
    count = 0
    n = i+1
    while n <= N:
        count += box[n-1]
        n += i + 1

    if count % 2 != a[i]:
        box[i] = 1

M = box.count(1)
print(M)

answer = [i+1 for i,x in enumerate(box) if x == 1]
if M > 0:
    print(' '.join(list(map(str,answer))))

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

#define ll long long
#define tc                int T;cin>>T;while(T--)
const int INF = 1e9 + 5;
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s, t; cin >> s >> t;
	vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));
	for (int i = 1; i <= s.size(); ++i)
		for (int j = 1 ; j <= t.size(); ++j)
		{
			if (t[j - 1] == s[i - 1])dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	// cout << dp[s.size()][t.size()];
	int i = s.size();
	string ans = "";
	int j = t.size();
	while (i > 0 && j > 0) {
		if (t[j - 1] == s[i - 1]) {
			ans.push_back(t[j - 1]);
			i--; --j;
		}
		else if (dp[i][j - 1] >= dp[i - 1][j])--j;
		else --i;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 35712
# vim: fileencoding=utf-8

from collections import Counter

def read_input():
    return input()

def check_beauty(s):
    """
    >>> check_beauty("abaccaba")
    Yes
    >>> check_beauty("hthth")
    No
    """
    checker = Counter(s)
    checker_key = [i[1] for i in checker.items() if not i[1] % 2 == 0]

    if len(checker_key) > 0:
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':

    # import doctest
    #
    # doctest.testmod()

    s = read_input()

    check_beauty(s)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define SWAP(x,y,z) {if ( y > z ) swap(y,z); if ( x > y ) swap(x,y); if (y > z) swap(y,z);}


double const eps = 1e-10;
double const pi = 3.1415926535;
ll const mod = 1e9+7;


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

    ll a,b,nod;
    cin >> a >> b;
    nod = __gcd(a,b);
    cout << a*b/nod;

    return 0;
    // 274751WM
}


Measured memory_bytes: 256
from numpy import*;B=searchsorted;a,b=split(int32(open(0).read().split()[1:]),2);c=0;l=2**29
while l:h=l;l//=2;y=sort(hstack((b%h-h,b%h)));c+=sum(B(y,h-a%h)-B(y,l-a%h))%2*l
print(c)

Measured memory_bytes: 59256
import sys
iput = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

def gcd(big, small):
    if small == 0:
        return big
    else:
        return gcd(small, big % small)

# gcd(a, b) * lcm(a, b) == a * b
def lcm(a, b):
    # 除算を先にしてオーバーフローのリスクを軽減する
    # FYI: https://qiita.com/drken/items/0c88a37eec520f82b788#2-2-%E5%8D%98%E7%B4%94%E3%81%AA%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0%E3%82%B2%E3%83%BC
    return (a // gcd(a, b)) * b

print(lcm(a, b))


Measured memory_bytes: 61416
#include<bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define dbug(a) cerr<<#a<<" : "<<a<<endl;
#define For(i,n) for(int i =0;i<n;i++)
#define FOR(i,a,b) for(int i =a;i<b;i++)
#define inf 100000
using namespace std;
int n;
ll a[inf];
ll sum[inf];

bool eqsig(ll a, ll b){
    if(a<0 && b>0)
        return true;
    if(a>0 && b<0)
        return true;
    return false;
}

ll solve(){
    ll ans=0;
    For(i,n-1){
        sum[i+1]=sum[i]+a[i+1];
        if(eqsig(sum[i],sum[i+1]))
            continue;
        if(sum[i]<0){
            ans-=(sum[i+1]-1);
            sum[i+1]=1;
        }
        if(sum[i]>0){
            ans+=(sum[i+1]+1);
            sum[i+1]=-1;
        }

    }
    return ans;
}

int main(){


    #ifdef magUNbos
        freopen("in","r",stdin);
        freopen("out","w",stdout);
    #endif // magUNbos


        cin>>n;
        For(i,n)
            cin>>a[i];
        sum[0]=a[0];
        ll aa,bb;
        if(a[0]==0){
            sum[0]=1;
            aa=solve()+1;
            sum[0]=-1;
            bb=solve()+1;
        }else
        if(a[0]>0){
            aa=solve();
            sum[0]=-1;
            bb=solve()+a[0]+1;
        }
        else if(a[0]<0){
            aa=solve();
            sum[0]=1;
            bb=solve()-(a[0]-1);
        }
        cout<<min(aa,bb)<<endl;




}


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


long long int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


int main(){
  int N,O;
  cin >> N;
  if(N<600){
    O = 8;
  }else if(N<800){
    O = 7;
  }else if(N<1000){
    O = 6;
  }else if(N<1200){
    O = 5;
  }else if(N<1400){
    O = 4;
  }else if(N<1600){
    O = 3;
  }else if(N<1800){
    O = 2;
  }else{
    O = 1;
  }
  
  cout << O <<endl;
    
  return 0;
}


long long int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


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

// 最大値を求めるセグメント木
struct SegmentTree {
private:
    int n;
    vector<ll> node;

public:
    SegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = max(node[2*i+1], node[2*i+2]);
    }

    void update(int x, ll val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }

    ll getmax(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];

        ll vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
};


int main(){
	
	int n;
	cin >> n;
	vector<ll> h(n), a(n);
	rep(i,n){
		cin >> h[i];
		h[i]--;
	}
	rep(i,n) cin >> a[i];
	
	SegmentTree seg( vector<ll>(n,0) );
	
	
	vector<ll> dp(n);
	rep(i,n){
		dp[h[i]] = a[i] + seg.getmax(0,h[i]);//findmax( dp, h[i] );
		seg.update(h[i], dp[h[i]]);
	}
	
	ll res = 0;
	rep(i,n){
		res = max( res, dp[i] );
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 9088
import sys
from typing import List


if __name__ == "__main__":
    num_matrix = int(input())
    matrices: List[List[int]] = []
    for _ in range(num_matrix):
        matrices.append(list(map(lambda x: int(x), input().split())))
    dp = [[sys.maxsize] * num_matrix for i in range(num_matrix)]
    for i in range(num_matrix):
        dp[i][i] = 0

    for l in range(1, num_matrix):
        for i in range(num_matrix - l):
            row = matrices[i][0]
            col = matrices[i + l][1]
            dp[i][i + l] = min(row * matrices[j][1] * col + dp[i][j] + dp[j + 1][i + l]
                               for j in range(i, i + l))

    print(f"{dp[0][num_matrix - 1]}")



Measured memory_bytes: 7420
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;


int x[100000];
int xp[100000], xm[100000];

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
ll Max(ll a, ll b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){
	int n,k;
	scanf("%d%d", &n,&k);
	REP(i, n) {
		scanf("%d", &x[i]);
		if (x[i] == 0)k--;
	}
	int rcnt = 0, lcnt=0;
	REP(i, n) {
		if (x[i] > 0)xp[rcnt++] = x[i];
	}
	RREP(i, n) {
		if (x[i] < 0)xm[lcnt++] = abs(x[i]);
	}
	int ans = 1e9;
	if (rcnt >= k) {
		ans = Min(ans, xp[k - 1]);
	}
	//PRINTD(ans);
	if (lcnt >= k) {
		ans = Min(ans, xm[k - 1]);
	}
	//PRINTD(ans);
	REP(i, k) {
		int r = i, l = k - 2 - i;
		if (r >= rcnt || l >= lcnt)continue;
		ans = Min(ans,xp[r] * 2 + xm[l]);
		//PRINTD(ans);
	}
	REP(i, k) {
		int l = i, r = k - 2 - i;
		if (r >= rcnt || l >= lcnt)continue;
		ans = Min(ans, xm[l] * 2 + xp[r]);
		//PRINTD(ans);
	}
	PRINTD(ans);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>i_i;
int main() {
	char s[4];
	string ans="Good";
	for(int i=0;i<4;i++) cin>>s[i];
	for(int i=0;i<3;i++){
		if(s[i]==s[i+1]){
			ans="Bad";
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	var l = make([]int, n)
	for i := 0; i < n; i++ {
		l[i] = nextInt()

		if i > 0 {
			if x := l[i] - l[i-1]; x > 0 {
				l[i]--
			} else if x == 0 {
			} else {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 3072
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

#define size_max 100+10

#define Y first
#define X second

int mx[4] = { 1,-1,0,0 };
int my[4] = { 0,0,1,-1 };

int map[size_max][size_max];


void paint(int c, int y, int x, int H, int W)
{
	int i, j;
	for (i = y; i < y + H; i++)
	{
		for (j = x; j < x + W; j++)
		{
			map[i][j] = c;
		}
	}
}


void check(int w, int h)
{
	int i, j;
	for (i = 0; i <= h + 1; i++)
	{
		for (j = 0; j <= w + 1; j++)
		{
			cout << map[i][j];
		}
		cout << endl;
	}
}


typedef pair<int, int> PR;

int main(void)
{
	PR now, tmp;
	queue<PR> QU;

	int w, h;
	int xs, ys, xg, yg, n;
	int c, d, set_x, set_y;

	int i, j;

	while ((cin >> w >> h), w != 0 && h != 0)
	{
		memset(map, 0, sizeof map);

		cin >> xs >> ys >> xg >> yg >> n;

		for (i = 0; i < n; i++)
		{
			cin >> c >> d >> set_x >> set_y;

			if (d == 0)
			{
				paint(c, set_y, set_x, 2, 4);
			}
			else
			{
				paint(c, set_y, set_x, 4, 2);
			}
		}

		//check(w, h);

		if (map[ys][xs] == 0)
		{
			cout << "NG\n";
			continue;
		}

		c = map[ys][xs];

		//cout << "C=" << c << endl;

		now = make_pair(ys, xs);
		QU.push(now);

		bool goal = false;
		while (!QU.empty())
		{
			now = QU.front();
			QU.pop();

			if (map[now.Y][now.X] == c)
			{
				map[now.Y][now.X] = -1;

				if (now.Y == yg && now.X == xg)
				{
					goal = true;
					while (!QU.empty())
					{
						QU.pop();
					}
					break;
				}

				for (i = 0; i < 4; i++)
				{
					if (map[now.Y + my[i]][now.X + mx[i]] == c)
					{
						tmp = make_pair(now.Y + my[i], now.X + mx[i]);
						QU.push(tmp);
					}
				}
			}
		}

		if (goal)
		{
			cout << "OK\n";
		}
		else
		{
			cout << "NG\n";
		}

	}

	return 0;
}


Measured memory_bytes: 2988
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

Measured memory_bytes: 3676
fun main(args: Array<String>) {
    val (N, M) = listOfIntg()
    val P = listOfIntg(-1)
    val uf = UnionFind(N)
    repeat(M) { m->
        val (x, y) = listOfIntg(-1)
        uf.union(x, y)
    }
    var ans = 0
    repeat(N) { n->
        if (uf.isSame(n, P[n])) ans += 1
    }
    println(ans)
}

class UnionFind(n: Int) {
    var rank: IntArray
    var par:  IntArray
    var size: IntArray
    init {
        this.rank = IntArray(n) { 0 }
        this.par  = IntArray(n) { it }
        this.size = IntArray(n) { 1 }
    }
    fun union(x: Int, y: Int): Boolean {
        var rx = this.root(x)
        var ry = this.root(y)
        if (rx == ry) return false
        if (this.rank[rx] < this.rank[ry]) {
            val w = rx
            rx = ry
            ry = w
        } else if (this.rank[rx] == this.rank[ry]) {
            this.rank[rx] += 1
        }
        this.par[ry] = rx
        this.size[rx] += this.size[ry]
        return true
    }
    fun find(x: Int): Int {
        if (this.par[x] == x) return x
        else {
            this.par[x] = this.find(this.par[x])
            return this.par[x]
        }
    }
    fun isSame(x: Int, y: Int) = this.root(x) == this.root(y)
    fun size(x: Int): Int = this.size[this.find(x)]
    fun root(x: Int): Int = this.find(x)
    fun unite(x: Int, y: Int) = this.union(x, y)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfIntg(d: Int = 0) = listOfString().map { it.toInt() + d }


Measured memory_bytes: 74476
#include<iostream>
#include<cstdio>
//1≤N≤100
//1≤M≤100
//1≤X≤N?1
//1≤A1<A2<…<AM≤N
//Ai≠X
//All values in input are integers.

using namespace std;
int f[105];
int main()
{
	int n,m,x;
	cin>>n>>m>>x;
     for(int i=1;i<=m;i++)
     {  int t;
     	cin>>t;
     	f[t]=1;
     }
     int num1=0,num2=0;
     for(int i=x;i<=n;i++)
	 {  
	 	num1+=f[i];
	 } 
	 for(int i=x;i>=0;i--)
	 {
	 	num2+=f[i];
	 }
	 cout<<min(num1,num2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(a))
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n,k;
	cin>>n>>k;
	cout<<n-k+1<<endl;
	return 0;
}

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
    
    
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int cnt=0;
    while(b<=a){
        cnt++;
        b*=2;
    }

    while(c<=b){
        cnt++;
        c*=2;
    }

    if(cnt<=k){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
    
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

/*

g++ -std=c++1z code.cpp
./a.out

*/

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

struct StGoods
{
  StGoods() : m_nPrice(0), m_nNum(0) { }

  int m_nPrice;
  int m_nNum;
};

void fnInput(int& rnTrgNum, vector<StGoods>& rvoGoods)
{
  int nGoodsSiz;
  cin >> nGoodsSiz >> rnTrgNum;
  rvoGoods.resize(nGoodsSiz);

  for (StGoods& roGoods : rvoGoods)
    cin >> roGoods.m_nPrice >> roGoods.m_nNum;
}

llong fnMinCost(int nTrgNum, const vector<StGoods>& cnrvoGoods)
{
  multimap<int, int> mpGoods;

  for (StGoods oGoods : cnrvoGoods)
    mpGoods.emplace(oGoods.m_nPrice, oGoods.m_nNum);

  llong nCost = 0;

  for (auto PGoods : mpGoods)
  {
    int nUsedNum = min(nTrgNum, PGoods.second);
    nCost += (llong)PGoods.first * nUsedNum;
    nTrgNum -= nUsedNum;

    if ( !nTrgNum ) break;
  }
  return nCost;
}
 
int main()
{
  int nTrgNum;
  vector<StGoods> voGoods;

  fnInput(nTrgNum, voGoods);
  cout << fnMinCost(nTrgNum, voGoods) << endl;

  return 0;
}

Measured memory_bytes: 8796
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i32 = input();
    let p: i32 = input();
    println!("{}", (a * 3 + p) / 2)
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(){
    
    int a,b,c;
    
    scanf("%d%d%d", &a, &b, &c);
    
    if ((a!=b && a!=c && c!=b) || (a==b && a==c)){
        printf("No\n");
    } else {
        printf("Yes\n");
    }

    return 0;
}

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


int main()
{
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	for(int i=k+1;i<=n;++i)ans+=n/i*(i-k)+(n%i!=0)*max(n-n/i*i-k+(k!=0),0ll);
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
int main(void){
    string t;
    string s;
    cin>>s>>t;
    ll a=0;
    ll m=t.size();
    rep(i,s.size()-t.size()+1){
        a=0;
        rep(j,t.size()){
            if(s[i+j]==t[j]){
                
            }
            else{
                a++;
            }
        }
        m=min(m,a);
    }
    cout<<m<<endl;
}


Measured memory_bytes: 3632
#include<stdio.h>

int gcd(int*, int*);

int main(void) {
    int x, y, result;
    scanf("%d%d",&x,&y);
    
    if(x>=y) result = gcd(&x, &y);
    else result = gcd(&y, &x);
    
    printf("%d\n", result);
    return 0;
}

int gcd(int *x, int *y) {
    int ret, mod;
    
    if(*y==0) ret= *x;
    else {
        mod = *x % *y;
        ret = gcd(y, &mod);
    }
    return ret;
}

Measured memory_bytes: 592
import math
n = int(input())
thress = [0]

tmp = 0
for i in range(30):
    if tmp > 10000000000:
        break
    tmp += 4 ** i
    thress.append(tmp)
    thress.append(tmp)

num = 0
s = ''
for i in range(len(thress)):
    if n == 0:
        print(0)
        break
    if num == n:
        print(s)
        break
    bit = math.ceil((n - thress[i]) / (2 ** i)) % 2
    if bit == 0:
        s = '0' + s
    else:
        s = '1' + s
        num += (-2) ** i


Measured memory_bytes: 3064