akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N, K; cin >> N >> K;
    string S; cin >> S;

    switch(S[K-1]) {
        case 'A': S[K-1] = 'a'; break;
        case 'B': S[K-1] = 'b'; break;
        case 'C': S[K-1] = 'c'; break;
    }

    cout << S << "\n";
}

Measured memory_bytes: 256
// I want to AC


#include <vector>
#include<stdio.h>
#include<string.h>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#include<queue>
#include<assert.h>
#define ll long long
#define MODD 1000000007
#define  pii  pair<int,int>
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
//#define  ll long long
using namespace std;
const int maxn = 1e9+7;
#define FOR(i, x, y) for (ll i = (x), _##i = (y); i < _##i; ++i)


ll exgcd(ll a, ll b, ll &x, ll &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll ret = exgcd(b, a % b, y, x);
	y -= a / b * x;
	return ret;
}
ll inv(ll a, ll M) {
	static ll x, y;
	assert(exgcd(a, M, x, y) == 1);
	return (x % M + M) % M;
}
//void gcd(ll a,ll b,ll &d,ll &x,ll &y){
//    if(!b){
//        d=a;x=1;y=0;
//    }else{
//        gcd(b,a%b,d,y,x);
//        y-=x*(a/b);
//    }
//}
//ll inv(ll a,ll n){
//    ll d,x,y;
//    gcd(a,n,d,x,y);
//    return d==1?(x+n)%n:-1;
//}
// LL get_inv(LL a, LL M) {
// static LL x, y;
// assert(exgcd(a, M, x, y) == 1);
// return (x % M + M) % M;
// }

//欧拉函数
ll euler(ll n) {
	ll rt = n;
	for (int i = 2; i * i <= n; i++)
		if (n % i == 0) {
			rt -= rt / i;
			while (n % i == 0)
				n /= i;
		}
	if (n > 1)
		rt -= rt / n;
	return rt;
}

bool st[1000005];
int primes[50005];
void prime(int n) {
	int cnt =0 ;
	for(int i=2; i<=n; i++) {
		if(!st[i]) {
			primes[cnt++]=i;
		}
		for(int j=0; j<cnt&&i*primes[j]<=n; j++) {
			st[primes[j]*i]=true;
			if(i%primes[j]==0) {
				break;
			}
		}
	}

}


vector<int > div(int x) {
	vector<int > res;
	for(int i=1 ; i<=x/i; i++) {
		if(x%i==0) {
			res.push_back(i);
			if(i!=x/i) res.push_back(x/i);
		}
	}
	sort(res.begin(), res.end());
	return res;
}
ll MOD = 1e9+7;
inline void read(int &x) {
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=f;
}

int lowbit(int x) {
	return x&(-x);
}
//ll bin(ll x, ll n, ll MOD) {
// ll ret = MOD != 1;
// for (x %= MOD; n; n >>= 1, x = mul(x, x, MOD))
// if (n & 1) ret = mul(ret, x, MOD);
// return ret;
// }
//ll C(ll n, ll m) { // m >= n >= 0
// if (m - n < n) n = m - n;
// if (n < 0) return 0;
// ll ret = 1;
// FOR (i, 1, n + 1)
// ret = ret * (m - n + i) % MOD * bin(i, MOD - 2, MOD) % MOD;
// return ret;
// }
// ll Lucas(ll n, ll m) { // m >= n >= 0
// return m ? C(n % MOD, m % MOD) * Lucas(n / MOD, m / MOD) % MOD : 1;
// }
//double dp[maxn],num[maxn];
//char ch [2500][2500];
int dp[100000]= {0};
int main() {
int  n; cin >>n;
int num =0x7f7f7f ;int cnt =0 ;
for(int i=0;i<n;i++){
	cin >>dp[i];
	num =min(num,dp[i]);
	if(num == dp[i])cnt++;
}
cout<<cnt<<endl;
	return 0;



}

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

int main(){
  int n,kaisu,k;
  int card[200];
  queue <int>kaku;
  queue <int>que;
  cin>>n>>kaisu;
  for(int i=0;i<2*n;i++){
    card[i]=i+1;
  }
  while(kaisu--){
    cin>>k;
    if(!k){
      for(int i=0,j=n;i<n;i++,j++){
	que.push(card[i]);
	que.push(card[j]);
      }
      for(int i=0;i<2*n;i++){
	card[i]=que.front();
	que.pop();
      }
    }
    else {
      for(int i=0;i<2*n;i++){
	kaku.push(card[i]);
      }
      int kou;
      for(int i=0;i<k;i++){
	kaku.push(kaku.front());
	kaku.pop();
      }
      for(int i=0;i<2*n;i++){
	card[i]=kaku.front();
	kaku.pop();
      }
    }
    while(!que.empty())que.pop();
    while(!kaku.empty())kaku.pop();
  }
    for(int i=0;i<2*n;i++){
      cout<<card[i]<<endl;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    ll N, A, B, ans = 0;
    cin >> N >> A >> B;
    ll block = N / (A + B);
    ans += block * A;
    ll other = N - (block * (A + B));
    if(other <= A) ans += other;
    else ans += A;
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<ll> w(n);
    REP(i, n) cin >> w[i];

    ll ans = LLINF;
    REP(i, n) {
        ll s1 = 0, s2 = 0;
        REP(j, i+1) s1 += w[j];
        FOR(j, i+1, n) s2 += w[j];
        chmin(ans, abs(s1-s2));
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  vector<ll> A(3), B(3);
  REP(i, 3) cin >> A[i];
  REP(i, 3) cin >> B[i];

  vector<vector<ll>> dp(4, vector<ll>(N+1, N));
  REP(i, 3) REP(w, N+1) {
    if (w >= A[i]) {
      dp[i+1][w] = max(dp[i][w], dp[i+1][w-A[i]] + B[i] - A[i]);
    } else {
      dp[i+1][w] = dp[i][w];
    }
  }

  int M = *max_element(ALL(dp[3]));
  vector<vector<ll>> dp2(4, vector<ll>(M+1, M));
  REP(i, 3) REP(w, M+1) {
    if (w >= B[i]) {
      dp2[i+1][w] = max(dp2[i][w], dp2[i+1][w-B[i]] + A[i] - B[i]);
    } else {
      dp2[i+1][w] = dp2[i][w];
    }
  }

  cout << *max_element(ALL(dp2[3])) << endl;

  return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll a, b;
  cin >> a >> b;

  if (a == 0 || b == 0 || a * b < 0) {
    cout << "Zero" << endl;
    return 0;
  }

  if (a > 0 && b > 0) {
    cout << "Positive" << endl;
    return 0;
  }

  if ((b - a + 1) % 2 == 0) {
    cout << "Positive" << endl;
  } else {
    cout << "Negative" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "Yes" : "No")
using namespace std;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n = 0, m;
	cin >> n >> m;
	if (m == 100) {
		cout << (int64_t)(pow(100, n))*(m + 1);
		return 0;
	}
	cout << (int64_t)(pow(100, n))*m;
}


Measured memory_bytes: 896
#include<cstdio>
const int MAXN = 100000;
int gcd(int x, int y) {
	return y == 0 ? x : gcd(y, x%y);
}
long long lcm(int x, int y) {
	return 1LL*x/gcd(x, y)*y;
}
char S[MAXN + 5], T[MAXN + 5];
int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	scanf("%s%s", S, T);
	long long m = 0, n = 0;
	while( m <= M && n <= N ) {
		if( S[n] != T[m] ) {
			puts("-1");
			return 0;
		}
		m += M/gcd(N, M);
		n += N/gcd(N, M);
	}
	printf("%lld\n", lcm(N, M));
}

Measured memory_bytes: 384
n, l = map(int, input().split())
if l >= 0:
    print((n - 1) * l + (n * (n + 1)) // 2 - (n - 1) - 1)
else:
    if n >= -l + 1:
        print(n * l + (n * (n + 1)) // 2 - n)
    else:
        print((n - 1) * l + (n * (n + 1)) // 2 - (n - 1) - n)


Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n;
ll two_pow[61];

bool C(ll v){
	ll cnt=0;
	for(int i=1;i<=60;i++){
		cnt+=n/two_pow[i];
		cnt-=(n-v)/two_pow[i];
		if(cnt<=-(1LL<<60))return false;
		cnt-=v/two_pow[i];
		if(cnt>=(1LL<<60))return true;
		if(cnt<=-(1LL<<60))return false;
	}
	return cnt>0LL;
}

int main(void){
	two_pow[0]=1;
	for(int i=0;i<60;i++){
		two_pow[i+1]=two_pow[i]*2LL;
	}
	scanf("%lld",&n);
	if(n%2LL==0){
		printf("%lld\n",1LL);
		return 0;
	}
	ll l=1;
	while(l<n){
		if(C(l))break;
		else l*=2LL;
	}
	if(l>=n){
		printf("%lld\n",n+1LL);
	}else{
		printf("%lld\n",l);
	}
	return 0;
}

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

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

const long long INF = 1LL << 60;
const long long mod = 1000000007;


int main(void){
   int n; cin >> n;
   vector<int> a(n);
    ll sum = 0;
    for(int i=0;i<n;i++){
	cin >> a[i];
	sum += a[i];
    }
    ll ans = 10000000000;
    ll tmp=0;
    for(int i=0;i<n-1;i++){
	tmp += a[i];
	ans = min(ans,abs(tmp-(sum-tmp)));
    }
    cout << ans << endl;
   return 0;
}


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

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const int64_t LINF = 1000000000000000; // = 10^15

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

//ライブラリ終わり
 
int main() {
  string S;
  cin >> S;
  int A, Z;
  for (int i = 0; i < INF; i++) {
    if (S.at(i) == 'A') {
      A = i;
      break;
    }
  }
  int T = S.size();
  for (int i = T - 1; i >= 0; i--) {
    if (S.at(i) == 'Z') {
      Z = i;
      break;
    }
  }
  cout << Z - A + 1 << endl;
}


Measured memory_bytes: 3712
import sys
input=sys.stdin.buffer.readline

import numpy as np

N = int(input())
L=list(map(int,input().split()))
P = np.array(L,np.int32)
# 累積の比較
Q = np.minimum.accumulate(P)
answer = np.count_nonzero(P <= Q)

print(answer)

Measured memory_bytes: 29380
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
 int n;
  cin>>n;
 string s;
  cin>>s;
  int l=0,r=0;
  string ans="";
  //////////////////////
  rep(i,0,n){
   if(s[i] =='(') l++;
    else r++;
   ////////////
    if(r>l) {
     ans+='(';
      r--;
    }
   
  }
  ans+=s;
  if(l>r){
    rep(i,0,l-r){
     ans+=')'; 
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

template <typename S>   //semi group
struct UnionFind
{
    using F = function<S(S, S)>;
    
    const F f;
    
    vector<int> par, rank;
    vector<S> dat;
    
    UnionFind(int n, const F f = [](S a, S b){return a + b;}) : f(f){
        par.resize(n);
        rank.resize(n);
        dat.assign(n, 1);
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int find(int i){
        if(i == par[i]) return i;
        return par[i] = find(par[i]);
    }
    
    bool same(int i, int j){
        return find(i) == find(j);
    }
    
    void unite(int i, int j){
        if(same(i, j)) return;
        i = find(i), j = find(j);
        if(rank[i] < rank[j]){
            par[i] = j;
            dat[j] = f(dat[i], dat[j]);
        }
        else{
            par[j] = i;
            dat[i] = f(dat[i], dat[j]);
            if(rank[i] == rank[j]) rank[i]++;
        }
    }
    
    S query(int i){
        return dat[find(i)];
    }
};

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind<int> uf(n);
    int w[100005];
    fill(w, w + n, 1);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        w[a]++;
        w[b]++;
        uf.unite(a, b);
    }
    vector<int> v[100005];
    for(int i = 0; i < k; i++){
        int c, d;
        cin >> c >> d;
        c--; d--;
        v[c].push_back(d);
        v[d].push_back(c);
    }
    for(int i = 0; i < n; i++){
        int ans = uf.query(i);
        ans -= w[i];
        for(int j : v[i]){
            if(uf.same(i, j)) ans--;
        }
        cout << ans << " ";
    }
    cout << endl;
}

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

int main(void) {
    string N;
    cin >> N;

    int size = N.size();
    string ichi = N.substr(size-1, 1);
    int num = atoi(ichi.c_str());

    if (num == 2 || num == 4 || num == 5 || num == 7 || num == 9) {
        cout << "hon" << endl;
    } else if (num == 0 || num == 1 || num == 6 || num == 8) {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
    return 0;
}

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

#define strlength 101

int main () {
	int count;
	char player1[strlength],player2[strlength];
	int point1 = 0,point2 = 0;
	int i,j;
	
	scanf ("%d",&count);
	
	for (i = 0;i < count;i ++) {
		scanf ("%s %s",&player1,&player2);
		
		for (j = 0;j < strlength;j ++) {
			if (strcmp (player1,player2) == 0) {
			    point1 ++;
			    point2 ++;
			    break;
			}
			
			if (player1[j] == '\0' || player2[j] == '\0') {
				if (player1[j] == '\0') {
					point2 += 3;
				} else if (player2[j] == '\0') {
					point1 += 3;
				}
				break;
			} 

			if (player1[j] != player2[j]) { 
			    if (player1[j] > player2[j]) {
				    point1 += 3;
				    break;
			    } else if (player1[j] < player2[j]) {
				    point2 += 3;
				    break;
			    } 
			}
			
		}
	}
	
	printf ("%d %d\n",point1,point2);
	
	return 0;
}


Measured memory_bytes: 2124
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
  int H,W,i,j,k;
  scanf("%d %d",&H,&W);
  char sky[H][W],value[H][W];
  for(i=0;i<H;i++) scanf("%s",sky[i]);
  for(i=0;i<H;i++)
    for(j=0;j<W;j++)
    {
      if(sky[i][j]=='c') value[i][j]=0;
      else value[i][j]=-1;
    }
    for(i=0;i<H;i++)
    {
      for(j=1;j<W;j++)
      {
        if((value[i][j-1]!=-1)&&(value[i][j]<0) )value[i][j]=value[i][j-1]+1;
      }
    }
    for(i=0;i<H;i++)
    {
      for(j=0;j<W-1;j++)
      {
        printf("%d ",value[i][j]);
      }
      printf("%d",value[i][W-1]);
      printf("\n");
    }

  return 0;
}



Measured memory_bytes: 2100
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if x == i*500 + j*100 + k*50:
        ans+= 1
print(ans)

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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}

ll fastExpo(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n % 2)
            res = res * a;
        n /= 2;
        a = a * a;
    }
    return res;
}

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

int main()
{
    int x, y, f = 0;
    cin >> x >> y;

    For(i, x + 1) if (i * 2 + (x - i) * 4 == y) f = 1;
    if (!f)
        cout << "No\n";
    else
        cout << "Yes\n";

    cerr << "execution time is: " << tick() << "\n";
}


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

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    int c1 = max(max(a,b),c);
    int c2 = a+b+c-c1;
    if(c1==c2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int N, u, v, w;
vector<pair<int, int>> G[100000];
bool visited[100000];
int color[100000];
ll sum = 0;

void dfs(int cur, int past) {
	for (auto next:G[cur]) {
		// termination conditions
		if (next.first == past) continue;
		// operations
		visited[next.first] = true;
		if ((color[cur] + next.second) % 2 != 0){
			color[next.first] = 1;
		} else {
			color[next.first] = 0;
		}
		// next
		dfs(next.first, cur);
	}
	return;
}

int main() {
	cin >> N;
	rep(i, N-1) {
		cin >> u >> v >> w;
		u--, v--;
		G[u].push_back(make_pair(v, w));
		G[v].push_back(make_pair(u, w));
	}
	visited[0] = true;
        color[0] = 0;
        dfs(0,0);
	rep(i, N) {
		print(color[i]);
	}
	
}


Measured memory_bytes: 8448
#include <iostream>
using namespace std;

int getDivisors(int n) {
    int count = 0;
    for(int i=1; i*i<=n; i++) {
        if(n%i==0) {
            count++;
            if(i!=n/i)
              count++;
        }
    }
    return count;
}

int main(void){
    int N;
    cin >> N;
    
    int count=0;
    for(int c=1; c<N; c++) {
        int ab = N - c;
        int div = getDivisors(ab);
        count+=div;
    }
    cout << count;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 1e3 + 13;
const int M = 5e5 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif

    ll n, a, b;
    cin >> n >> a >> b;
    ll x = 0;
    if ((b-a) & 1){
        if (a-1 < n-b){
                x += a;
            b -= a;
            a = 1;

        }
        else{
            x += n-b+1;
            a += n-b+1;
            b = n;

        }
    }
    cout <<(b-a)/2 + x;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    string o,e;
    cin >> o;
    cin >> e;
    string ret = "";
    for(int i=0;i<e.size();i++){
        ret += o[i];
        ret += e[i];
    }
    if(o.size() > e.size()){
        ret += o[o.size()-1];
    }
    cout << ret;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<utility>
#define mod 998244853 
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, s=0;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < n; i++)
        for(int j = i+1; j < n; j++)
            s+=a[i]*a[j];
    cout << s << '\n';
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 200001;

vector<string> A;
vi ind;

bool comp(ll i, ll j){
    return sz(A[i]) < sz(A[j]);
}

vector<vl> H(MAXN, vl());
unordered_map<ll,ll> M;
const ll base = 12738481;

ll hh(ll c, ll x){
    return c+base*x;
}

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

    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d,e;

    cin >> n;
    rep(c1,0,n){
        string s;
        cin >> s;
        A.push_back(s);
        ind.push_back(c1);

        ll h1 = 0;
        ll h2 = 0;
        H[c1].push_back(0);
        m = sz(s);
        for(int c2 = m-1; c2 >= 0; c2--){
            h1 *= base;
            h1 += (s[c2]-'a'+1);
            h1 %= big;

            h2 *= base;
            h2 += (s[c2]-'a'+1);
            h2 %= big2;

            ll tmp = h1*big2+h2;
            H[c1].push_back(tmp);
        }
        reverse(all(H[c1]));
    }

    sort(all(ind),comp);
    ll ans = 0;
    trav(i, ind){
        bool seen[26] = {0};
        m = sz(A[i]);
        rep(c1,0,m){
            ll L = A[i][c1]-'a';
            if(!seen[L]){
                seen[L] = 1;
                rep(c2,c1+1,m+1){
                    ll tmp = hh(L, H[i][c2]);
                    if(M.find(tmp) != M.end()){
                        ans++;
                    }
                }
            }
        }
        ll tmp = hh(A[i][0]-'a', H[i][1]);
        if(M.find(tmp) == M.end()){
            M[tmp] = 1;
        }
    }
    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 38360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for(auto v:(V))cout<<v<<" "<<endl
inline int GCD(int a, int b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;

int main()
{
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vll a(x);
    vll b(y);
    vll c(z);
    rep(i, x)
    {
        cin >> a.at(i);
    }
    rep(i, y)
    {
        cin >> b.at(i);
    }
    rep(i, z)
    {
        cin >> c.at(i);
    }
    sort(ALL(a), greater<ll>());
    sort(ALL(b), greater<ll>());
    sort(ALL(c), greater<ll>());
    vll ans;
    ll shikii = a.at(min(x-1, 15))+b.at(min(y-1, 15))+c.at(min(z-1, 15));
    ll anstemp = 0;
    rep(p, x)
    {
        rep(q, y)
        {
            rep(r, z)
            {
                anstemp = a.at(p)+b.at(q)+c.at(r);
                if (p*q*r > 3000)
                {
                    break;
                }
                ans.push_back(anstemp);
            }
        }
    }
    sort(ALL(ans), greater<ll>());

    rep(i, k)
    {
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 35176
#include<iostream>
using namespace std;
int main() {
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; s[i]; i++) {
        int cnt = 0;
        if (s[i] == 'R') {
            while (s[i] == 'R') {
                cnt++;
                i++;
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3196
class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  read<T>(parser: (v: string) => T): () => T {
    return () => {
      const ret = parser(this.input[this.pointer]);
      this.pointer++;
      return ret;
    };
  }
  int = this.read((str) => parseInt(str, 10));
  ints = (length: number): number[] => {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  };
  str = (): string => {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  };
  strs = (length: number): string[] => {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  };
  bint = (): bigint => {
    const ret = BigInt(this.input[this.pointer]);
    this.pointer++;
    return ret;
  };
  bints = (length: number): bigint[] => {
    let ret: bigint[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.bint());
    }
    return ret;
  };
}
function rep(a: number, b: number) {
  let arr = [];
  for (let i = a; i < b; i++) arr.push(i);
  return arr;
}

function Main({ int, str, strs, ints, bint, bints }: NormalInput) {
  const N = int();
  const A = bints(N);
  let minus: Map<bigint, number> = new Map();
  let plus: Map<bigint, number> = new Map();
  for (let i = 0; i < N; i++) {
    const m = A[i] - BigInt(i);
    const p = A[i] + BigInt(i);
    minus.set(m, (minus.has(m) ? minus.get(m)as number : 0) + 1);
    plus.set(p, (plus.has(p) ? plus.get(p)as number : 0) + 1);
  }
  let ans = 0n;
  minus.forEach((m, i) => {
    if (plus.has(-i)) {
      const p = plus.get(-i) as number;
      ans += BigInt(m * p);
    }
  });
  console.log(ans + "");
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 103484
#include<bits/stdc++.h>
using namespace std; 
char a[3], b[3]; 
int cnt; 

int main()
{
	for(int i = 0; i < 3; i ++)
	    cin >> a[i]; 
	for(int i = 0; i < 3; i ++)
	    cin >> b[i]; 
	for(int i = 0; i < 3; i ++)
	{
		if(a[i] == b[i])
		cnt ++; 
	}
	cout << cnt << endl; 
	return 0; 
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String dirs = sc.next();
        int e = 0;
        int s = 0;
        int w = 0;
        int n = 0;
        int i = 0;
        for (char dir : dirs.toCharArray()) {
            i++;
            if (i > 1000) {
                System.out.println("No");
            }
            switch (dir) {
                case 'E':
                    e++;
                    break;
                case 'S':
                    s++;
                    break;
                case 'W':
                    w++;
                    break;
                case 'N':
                    n++;
                    break;
                default:
                    System.out.println("No");
                    System.exit(0);
            }
        }

        if ((e > 0 && w == 0)
                || (e == 0 && w > 0)
                || (n == 0 && s > 0)
                || (n > 0 && s == 0)) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 9428
#include<stdio.h>

int main(void) {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a == 1 || b == 1) {
		printf("YES");
		return 0;
	} else {
		for (int i = 0; i < b; i++) {
			if (a * i % b == c) {
				printf("YES");
				return 0;
			}
		}
		printf("NO");
		return 0;
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {      
       ll n,ans=0,m,k,i,j=1,sum=0;
       cin>>n>>m>>k;
       vector <ll> a(n+1),b(m+1);
       for(i=1;i<=n;i++)
        cin>>a[i],a[i]+=a[i-1];
       for(i=1;i<=m;i++)
        cin>>b[i],b[i]+=b[i-1];
        j=m;
        for(i=0;i<=n;i++)
        {
            if(a[i]>k)
             break;
            while(a[i]+b[j]>k)
             j--;
            ans=max(ans,i+j);  
        }
       cout<<ans;
   }
}

Measured memory_bytes: 6364
#include <stdio.h>
#define mod 1000000007
 
int main(){
  int N;
  scanf("%d",&N);
  int a[(N+1)/2];
  int A;
  for(int i=0;i<(N+1)/2;i++)a[i]=0;
  for(int i=0;i<N;i++){
    scanf("%d",&A);
    a[A/2]++;
  }
 
  int flag=1;
  int cnt=0;
  for(int i=0;i<(N+1)/2;i++){
    if(i==0&&N%2!= 0){
      if(a[i]!=1)
        flag=0;
    }
    else{
      if(a[i]!=2) flag=0;
      else cnt++;
    }
  }
  long long ans=1;
  while(cnt>0){
    ans*=2;
    ans%=mod;
    cnt--;
  }
  if(flag){
    printf("%lld\n",ans);
  }
  else{
    printf("0\n");
  }
 
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

#define pai 3.14159265358979

int main (void)
{
	double s, m, r;

	scanf("%lf", &r);

	s = r * r * pai;
	m = 2 * r * pai;

	printf("%.6f %.6f\n", s, m);
	return 0;
}

Measured memory_bytes: 652
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int c = 0, c2 = 0, c4 = 0;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            if ((a[i] = scanner.nextInt()) % 4 == 0) c4++;
            else if (a[i] % 2 == 0) c2++;
            else c++;
        }

        System.out.println(c - (c2 == 0 ? 1 : 0) <= c4 ? "Yes" : "No");
    }
}

Measured memory_bytes: 50732
#include<iostream>
#include<math.h>
#include<climits>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<unordered_set>
#include<unordered_map>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack> 
using namespace std;
#define ff              first
#define ss              second
#define int             long long int
#define ull             unsigned long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define si              set<int>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1e9+7
#define inf             1e18
#define sp(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(t)            int t; cin>>t; while(t--)
#define asc(i,a,n)      for (int i=a;i<n;i++)
#define dsc(i,a,n)      for (int i=n-1;i>=a;i--)
#define sz(x)           ((int)(x).size())
#define flg             if(flag==0)cout<<"Yes"<<endl;else{cout<<"No"<<endl;}
#define FLG             if(flag==0)cout<<"YES"<<endl;else{cout<<"NO"<<endl;}
#define input(arr,n)    for(int i=0; i<n ; i++) cin>>arr[i];
#define output(arr,n)   for(int i=0; i<n ; i++) cout<<arr[i]<<" ";
#define fast            ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 


 
int32_t main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;

  int i=0;

  while(1)
  {
    if(i%2==0)
    {
        c=c-b;
        if(c<=0)
        {
            cout<<"Yes"<<endl;
            break;
        }

    }
    else
    {
        a = a-d;
        if(a<=0)
        {
            cout<<"No"<<endl;
            break;
        }
    }
    i++;
  }

   

}





Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define M 1005
#define N 105
#define B 12
using namespace std;

int HP_init, HP_Max, R, C, S;

string s[N], dir;

int cost[N*3], P, p[B];

int dp[M][(1<<B)], y[M], x[M], idx[N*3];

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

bool solve(){
  
  idx['U']=0; idx['R']=1;
  
  idx['D']=2; idx['L']=3;
  
  memset(dp,-1,sizeof(dp));
  
  dp[0][0]=HP_init;
  
  y[0]=0, x[0]=0;
  
  int m=dir.size();
  
  for(int i=0;i<m;i++){

    for(int j=0;j<(1<<P);j++){

      if(dp[i][j]<0) continue;
      
      y[i+1]=y[i]+dy[idx[(int)dir[i]]];
      
      x[i+1]=x[i]+dx[idx[(int)dir[i]]];

      for(int k=0;k<P;k++){

	if(j&(1<<k)) continue;
	
	int nhp=min(HP_Max,dp[i][j]+p[k]);
	
	dp[i][j|(1<<k)]=max(dp[i][j|(1<<k)],nhp);
	
	nhp=max(0,nhp-cost[(int)s[y[i+1]][x[i+1]]]);
	
	if(!nhp) continue;
	
	dp[i+1][j|(1<<k)]=max(dp[i+1][j|(1<<k)],nhp);
	
      }
      
      int nhp=max(0,dp[i][j]-cost[(int)s[y[i+1]][x[i+1]]]);
      
      if(!nhp) continue;

      dp[i+1][j]=max(dp[i+1][j],nhp);
    }
    
  }

  for(int i=0;i<(1<<P);i++)
    if(dp[m][i]>0) return true;
  
  return false;
}

int main(){

  while(1){
    
    cin>>HP_init>>HP_Max;

    if(!HP_init&&!HP_Max) break;

    cin>>R>>C;
    
    for(int i=0;i<R;i++) cin>>s[i];

    int T;

    cin>>T;
    
    for(int i=0;i<T;i++){
      
      char c;
      int d;

      cin>>c>>d;

      cost[(int)c]=d;
    }
    
    cin>>S;

    dir="";
    
    for(int i=0;i<S;i++){
      
      char c;
      int num;
      
      cin>>c>>num;

      for(int j=0;j<num;j++) dir+=c;
      
    }
    
    cin>>P;
    
    for(int i=0;i<P;i++) cin>>p[i];

    if(solve()) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 19220
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  int N, W;
  long long w[105], tv;
  vector<long long> v[4];
  cin>>N>>W;
  REP(i,0,N){
    cin>>w[i]>>tv;
    v[w[i]-w[0]].push_back(tv);
  }
  REP(i,0,4){
    sort(v[i].begin(), v[i].end(), greater<long long>());
  }
  long long ans = 0;
  REP(i,0,v[0].size()+1){
    REP(j,0,v[1].size()+1){
      REP(k,0,v[2].size()+1){
        REP(l,0,v[3].size()+1){
          long long sum = 0;
          REP(ii,0,i) sum += v[0][ii];
          REP(ii,0,j) sum += v[1][ii];
          REP(ii,0,k) sum += v[2][ii];
          REP(ii,0,l) sum += v[3][ii];
          if(i*w[0] + j*(w[0]+1) + k*(w[0]+2) + l*(w[0]+3) <= W) ans = max(ans, sum);
        }
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

struct info {
    ll yen, stock;
};

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    cin >> A;
    // 0 is purchase, 1 is sale
    vector<vector<info>> dp(N + 1, vector<info>(2));
    dp[0][0] = {1000, 0};
    dp[0][1] = {1000, 0};
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < i; j++) {
            {
                // purchase
                auto &update = dp[i][1];
                info check = {dp[j][0].yen % A[i - 1], dp[j][0].yen / A[i - 1]};
                if (update.stock < check.stock || (update.stock == check.stock && update.yen < check.yen)) {
                    update = check;
                }
            }
            {
                // sale
                auto &update = dp[i][0];
                info check = {dp[j][1].stock * A[i - 1] + dp[j][1].yen, 0};
                if (update.yen < check.yen) update = check;
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i <= N; i++) chmax(ans, dp[i][0].yen);
    cout << ans << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int a,b,k;
  cin >> a >> b >> k;
  if(b-a+1<=2*k) {
    for(int i=a; i<=b; i++) {
      cout << i << endl;
    }
  }
  else {
    for(int i=a; i<=a+k-1; i++) {
      cout << i << endl;
    }
    for(int i=b-k+1; i<=b; i++) {
      cout << i << endl;
    }
  }
}

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

int main() {
    int n;
    cin >> n;
    if (n < 1000){
        cout << "ABC" << endl;
    }
    else{
        cout << "ABD" << endl;
    }
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void) {
	int s, buf, i;
	const int list[6] = {1,5,10,50,100,500};
	for(i = 0; 6 > i; i++){
		 scanf("%d", &buf);
		 s += buf*list[i];
	}
	printf("%d\n", s >= 1000 ? 1 : 0);
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; cin >> n; std::vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(begin(a), end(a)); reverse(begin(a), end(a));
	
	int now = std::accumulate(begin(a), end(a), 0);
	
	if(now % 10) {
		cout << now << endl;
	} else {
		for(int i = n - 1; i >= 0; i--) {
			if(a[i] % 10) {
				cout << now - a[i] << endl;
				return 0;
			}
		}
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) x.begin(), x.end()
#define pb  push_back
#define mb  make_pair
#define fi  first
#define se  second

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
const ll mod = 1000000007;

void solve()
{
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    int res = 0;

    res += min(a,k);
    k -= a;
    k -= b;
    if(k > 0)
    res -= min(c,k);
    cout << res;

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    //int t; cin >> t; while(t--)
    solve();
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


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

    int ans = 0;
    int bt = n+1;
    for(int i = 0; i < n; i++){
        if(a[i] < bt){
            ans++;
            bt = a[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4048
function Main(s){
  s = s.split("\n");
  var l = s[0].length;
  if(s[0] === s[1]){console.log("Yes");return;}
  for(var i = 0; i < l; i++){
    s[0] = s[0][l-1]+s[0].slice(0,-1);
    if(s[0] === s[1]){console.log("Yes");return;}
  }
  console.log("No");
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 21064
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int i = 1;
		int n = 0;
		
		while (true) {
			n = Integer.parseInt(br.readLine());
			if (n == 0) break;
			
			System.out.println("Case " + i + ": " + n);
			i++;
		}
	}
}

Measured memory_bytes: 31720
import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val S = sc.next()
    val K = sc.nextLong()

    def countOne: (Int, Char) = {
      var cnt = 0
      rep(S.length) { i =>
        if (S(i) == '1') cnt += 1
        else return (cnt, S(i))
      }
      (cnt, '1')
    }

    val (ones, next) = countOne
    val ans = if (ones >= K) '1' else next

    out.print(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


Measured memory_bytes: 25408
#include <stdio.h>
typedef long long ll;
int main() {
	int k;
	ll a, b;
	scanf("%lld %lld %d", &a, &b, &k);
	for (int i = 0; i < k; i++) {
		if (i % 2 == 0) {
			if (a % 2 == 1) {
				a--;
			}
			b += a / 2;
			a /= 2;
		} else {
			if (b % 2 == 1) {
				b--;
			}
			a += b / 2;
			b /= 2;
		}
	}
	printf("%lld %lld\n", a, b);
	return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
while True:
    n=input()
    if n==0:break
    dic=defaultdict(list)
    for i in range(n):
        L=raw_input().split()
        name,rslt=L[0],L[1:]
        dic[(rslt.count("0"),-rslt.count("1"),rslt.count("2"))].append(name)

    for i in  reversed(sorted(dic.keys())):
        for j in  dic[i]:
	    print j

Measured memory_bytes: 4624
/// @file a2.cpp
#include <cstdio>

/// @brief Counts palindromic numbers in the range.
int main() {
    int A, B, palindrome, i, count = 0;

    scanf("%d %d", &A, &B);

    for (i = 100; i <= 999; ++i) {
        palindrome = i * 100 + (i / 10 % 10) * 10 + (i / 100 % 10);
        
        if (A <= palindrome && palindrome <= B) {
            ++count;
        }
    }
    
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128