akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "5 7 5" ].parse.expand.solve == "Yes" );
	assert( [ "4 4 4" ].parse.expand.solve == "No" );
	assert( [ "4 9 6" ].parse.expand.solve == "No" );
	assert( [ "3 3 4" ].parse.expand.solve == "Yes" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split.to!( long[] );
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( long a, long b, long c )
{
	if( a == b && a != c ) return "Yes";
	if( a == c && a != b ) return "Yes";
	if( b == c && a != b ) return "Yes";
	return "No";
}


Measured memory_bytes: 256
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
ll len_t(ll n){
	return pow(2,n+2)-3;
}

ll pn[51];

ll tn[51];

ll dfs(ll n, ll x){
	// printf("dfs(%lld, %lld) len_t=%lld\n", n, x, len_t(n));
	if (n==0 & x==1){
		// printf("return 1\n");
		// dp[0][1] = 1;
		return 1;
	}
	else if (x<=1){
		// dp[0][0] = 0;
		return 0;
		// return dp[0][0];
	}
	else if (x>=len_t(n)-1){
		// cout << "return " << pow(2,n+1)-1 << endl;
		// printf("return %lld \n", pow(2,n+1)-1);
		// dp[n][x] = pow(2,n+1)-1;
		return pn[n];
	}
	// else if (x=len_t(n-1)+2){
	// 	printf("dfs(%lld, %lld) + 1\n", n-1, len_t(n-1));
		
	// 	return dfs(n-1, len_t(n-1)) + 1;
	// }
	else if (x>=len_t(n-1)+2){
		// printf("dfs(%lld, %lld) + ", n-1, len_t(n-1));
		// printf("dfs(%lld, %lld) + 1\n", n-1, x - len_t(n-1) - 2);
		return pn[n-1] + dfs(n-1, x - len_t(n-1) - 2) + 1;
		// return dp[n][x];
	}
	else{
		// dp[n][x] = dfs(n-1, x-1);
		return dfs(n-1, x-1);
	}
}
 

int main() {
	// 入力
	ll N, X;
	cin >> N >> X;
	
	// 解法
	REP(i,51){
		pn[i] = pow(2,i+1)-1;
	}
	
	REP(i,51){
		tn[i] = len_t(i);
	}
	// memset(dp, -1, sizeof(dp));
	ll ans = dfs(N,X);
	cout << ans << endl;
	
}


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

using namespace std;
using Graph = vector<vector<int>>;

vector<int> points;
vector<bool> seen;
void dfs(const Graph &G, int v, int add) {
    seen[v] = true;
    points[v] += add;

    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        dfs(G, next_v, points[v]);
    }
}

int main() {
    int N, Q;
    cin >> N >> Q;

    Graph G(N);
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        G.at(a-1).push_back(b-1);
        G.at(b-1).push_back(a-1);
    }

    points.assign(N, 0);
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        points.at(p-1) += x;
    }

    seen.assign(N, false);
    dfs(G, 0, 0);

    for (int i = 0; i < N; i++) {
        cout << points.at(i) << " ";
    }

    return 0;
}

Measured memory_bytes: 23552
xs = Array.new(4) {
  Array.new(3) {
    Array.new(10) { 0 }
  }
}

gets.to_i.times do 
  b,f,r,v = gets.split(" ").map(&:to_i)
  xs[b - 1][f - 1][r - 1] += v
end

puts xs.map {|building| 
  building.map {|floor| " " + floor.join(" ") }.join("\n")
}.join("\n" + "#" * 20 + "\n")

Measured memory_bytes: 8716
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int mod = 1e9+7;
const int mo = 1e9+7;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
int size[5050];
struct node{
	int to,next;
}e[100010];
ll base[5050],f[5050][5050],g[5050],h[5050],tot,n;
inline void add_edge(int from,int to){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;}
inline void Pre(int now,int ffa){
	size[now]=1;for(register int i=h[now];i;i=e[i].next){int to=e[i].to;if(to==ffa) continue;Pre(to,now);size[now]+=size[to];}
}
inline void DFS(int now,int ffa)
{
	for(register int i=h[now];i;i=e[i].next)
	{
		int to=e[i].to;if(to==ffa) continue;
		DFS(to,now);
	}
	f[now][1]=1;int las=1;
	for(int p=h[now];p;p=e[p].next)
	{
		if (e[p].to==ffa) continue;
			int y=e[p].to;
			for(register int i=1;i<=las;++i){
				g[i]=f[now][i];
				f[now][i]=0;
			}
			for(register int i=1;i<=las;++i)
				for(register int j=1;j<=size[y];++j){
					f[now][i+j]=(f[now][i+j]+g[i]*f[y][j])%mo;
					if (j%2==0)f[now][i]=(f[now][i]+mo-g[i]*f[y][j]%mo*base[j/2]%mo)%mo;
				}
		las+=size[y];
	}
}
int main()
{
	n=read();
	for(register int i=1,u,v;i<n;++i) u=read(),v=read(),add_edge(u,v),add_edge(v,u);
	base[0]=1;for(register ll i=1;i<=n;++i) base[i]=1ll*base[i-1]*(2*i-1)%mod;
	Pre(1,0);
	DFS(1,0);ll ans=0;
	for(register int i=1;i<=n;++i) if(i%2==0) ans=(ans+f[1][i]*base[i/2]%mod)%mod;
	cout<<ans%mod;
	return 0;
}

Measured memory_bytes: 198272
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;

int main(){

	string s;
	cin >> s;
	if(s=="AKIHABARA" || s=="AKIHABAR" || s=="AKIHABRA" || s=="AKIHBARA" || s=="KIHABARA"
	|| s=="AKIHABR" || s=="AKIHBAR" || s=="KIHABAR" || s=="AKIHBRA" || s=="KIHABRA" ||
	s=="KIHBARA" || s=="AKIHBR" || s=="KIHABR" || s=="KIHBAR" || s=="KIHBRA" || s=="KIHBR"){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

//int func(int i, int *h, map<int,int>* memo);

int main(){
    int N = 0;
    cin>>N;
    int h[N];
    for(int i = 0; i < N; ++i){
        cin >> h[i];
    }
//    map<int,int> memo;
    //int ans = func(N-1,h,memo);
    int memo[N];
    memo[0] = 0;
    memo[1] = abs(h[1] - h[0]);
    for(int j = 2; j < N; ++j){
        int a = memo[j-1] + abs(h[j] - h[j-1]);
        int b = memo[j-2] + abs(h[j] - h[j-2]);
        memo[j] = min(a,b);
    }
    int ans = memo[N-1];
    cout << ans << endl;
    return 0;
}

//int func(int i,int *h,map<int,int>* memo){
////    初期値の部分
//    if(i==0) return 0;
//    else if(i==1) return abs(h[1]-h[0]);
////    ２択の部分
//    auto it = memo->find(i-1);
//    int a = 0;
//    if(it != memo->end()){
//        a = it->second;
//    }else{
//        a = func(i-1,h,memo) + abs(h[i] - h[i-1]);
//    }
//    int b = 0;
//    auto it2 = memo->find(i-2);
//    if(it2 != memo->end()){
//        b = it2->second;
//    }else{
//        b = func(i-2,h,memo) + abs(h[i] - h[i-2]);
//    }
//    memo->insert(i,min(a,b));
//    return min(a,b);
//}





Measured memory_bytes: 1024
#include<iostream>
 
using namespace std;
const int MAX_N=1e3;
int data[MAX_N];
int main(){
    int m,nmi,nma;
    while(cin>>m>>nmi>>nma && nmi!=0){
        for(int i=0;i<m;i++)cin>>data[i];
        int ma=0;
        int ans=0;
        for(int i=nmi-1;i<nma;i++){
            if(ma<=data[i]-data[i+1]){
                ans=i+1;
                ma=data[i]-data[i+1];
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3080
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <set>
#include <limits.h>
#include <queue>

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define MOD 1000000007

using ll = long long;

using namespace std;

ll pow_mod(ll a, ll b, ll p) {
	if (b == 0)return 1;
	else if (b % 2 == 0)return (pow_mod(a*a, b / 2, p) % p);
	else return (pow_mod(a, b - 1, p)*a%p);
}

ll sum_digit(ll N) {
	int ans = 0;
	for (; N != 0;) {
		ans += N % 10;
		N /= 10;
	}
	return ans;
}

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

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

ll N;

int main(){
	scanf("%lld", &N);
	int x = ceil(sqrt(N));
	int factor;
	for (int i = x; i>0; i--) {
		if (!(N % i)) {
			factor = i;
			break;
		}
	}
	factor = N / factor;
	int ans = 0;
	for (; factor > 0; factor /= 10)ans++;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
    int n;
    scanf("%d", &n);
    int a[n], b[n];
    for (int i = 0; i < n; ++i){
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; ++i){
        b[a[i]-1] = i+1;
    }
    for (int i = 0; i < n; ++i){
        printf("%d ", b[i]);
    }
 
 
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	long long N;
	cin >> N;

	int K;
	cin >> K;

	int h;
	long long ans = 0;
	for (long long i = 0; i < N; i++) {
		cin >> h;
		if (h >= K) {
			ans += 1;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 998244353;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;

int main() {
    int n, s;
    cin >> n >> s;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    vector<mint> dp(s+1);
    dp[0] = mint(2).pow(n);
    mint a = mint(2).inv();
    for (int i = 0; i < n; ++i) {
        for (int j = s-v[i]; j >= 0; --j) {
            dp[j+v[i]] += dp[j]*a;
        }
    }
    cout << dp.back().val << "\n";
    return 0;
}

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

using namespace std;

int main()
{
   bool ym, my;
   int s, bef, aft;
   ym = my = false;

   cin >> s;

   aft = s % 100;
   bef = (s - aft) / 100;

   if(aft != 0 && bef != 0){
      if(bef <= 12){
         if(aft <= 12) ym = my = true;
         else my = true;
      }else if(bef > 12 && aft <= 12){
         ym = true;
      }
   }else if(bef == 0 && aft <= 12 && aft != 0){
      ym = true;
   }else if(bef <= 12 && bef != 0 && aft == 0){
      my = true;
   }

   if(ym){
      if(my){
         cout << "AMBIGUOUS" << endl;
      }else{
         cout << "YYMM" << endl;
      }
   }else if(my){
      cout << "MMYY" << endl;
   }else{
      cout << "NA" << endl;
   }

   return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

template <typename _Ty>
class BIT {
private:
    size_t m_n;
    std::vector<_Ty> m_vec;

public:
    BIT(size_t num) : m_n(num), m_vec(num + 1) {}
    // i 番目の要素に a を足す
    void add(size_t i, const _Ty& a) {
        for (++i; i <= m_n; i += i & (-i)) {
            m_vec[i] += a;
        }
    }
    // 区間[0, i)に対するクエリを実行する
    _Ty query(size_t i) const {
        _Ty res = 0;
        for (; i >= 1; i -= i & (-i)) {
            res += m_vec[i];
        }
        return res;
    }
    // 区間[i, j)に対するクエリを実行する
    _Ty query(size_t i, size_t j) const {
        return query(j) - query(i);
    }
    size_t size() const noexcept {
        return m_n;
    }
    void assign(const _Ty& a) {
        std::fill(m_vec.begin(), m_vec.end(), a);
    }
};

void solve() {
    ll N;
    cin >> N;
    Vl A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    Vl vec(N);
    for (ll i = 0; i < N; i++) {
        vec[i] = A[i] + (i + 1);
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());

    unordered_map<ll, ll> invec;
    ll l_vec = (ll)vec.size();
    for (ll i = 0; i < l_vec; i++) {
        invec[vec[i]] = i;
    }

    Vl nums(l_vec);
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        ll p = i + 1 - A[i];
        ll idx = lower_bound(vec.begin(), vec.end(), p) - vec.begin();
        if (idx < l_vec && vec[idx] == p) {
            ans += nums[idx];
        }

        ll q = A[i] + (i + 1);
        ++nums[invec[q]];
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 16140
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=1000005, INF=1e18;
lld pi=3.1415926535897932;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
vi prime;
bool isprime[N];
void pre()
{
    for(int i=2;i<N;i++)
    {
        if(isprime[i])
        {
            for(int j=i*i;j<N;j+=i)
            isprime[j]=false;
        }
        prime.pb(i);
    }
    return;
}
int32_t main()
{
    IOS;
    fill(isprime, true);
    pre();
    int n;
    cin>>n;
    int c=0;
    int l=prime.size();
    for(int i=0;i<l;i++)
    {
        if(n==1)
        break;
        if(n%prime[i]==0)
        {
            //c++;
            int z=0;
            while(n%prime[i]==0)
            {
                n/=prime[i];
                z++;
            }
            int j=1;
            while((((j+2)*(j+1))/2)<=z)
            j++;
            c+=j;
        }
    }
    if(n>1)
    c++;
    cout<<c;
}

Measured memory_bytes: 12580
import java.util.Scanner;

class Main {  
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int a = in.nextInt();
    int b = in.nextInt();
    System.out.println(gcd(a, b));
  }
  
  public static int gcd(int x, int y) {
    if      (y == 0) return x;
    else if (x < y)  return gcd(y, x);
    else if (x > y)  return gcd(y, x%y);
    else             return x;
  }
}

Measured memory_bytes: 17348
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin())
#define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin())
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int n = 0, w = 0, s = 0, e = 0;
  REPx(x, S)
  {
    if (x == 'N') ++n;
    else if (x == 'W') ++w;
    else if (x == 'S') ++s;
    else if (x == 'E') ++e;
  }
  if (n * s == 0 && (n || s)) cout << "No" << endl;
  else if (w * e == 0 && (w || e)) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main(void){
	long int A; 
	long int B;
	scanf("%ld", &A);
	scanf("%ld", &B);
	if(A%2==0 && B%2==0 || A%2==1 && B%2==1){
		printf("%ld", (A+B)/2);}
		else{
			printf("IMPOSSIBLE");
	}
	return 0;
}
	


Measured memory_bytes: 128
N=int(input())
S=input()
for t in ["SS", "SW", "WS", "WW"]:
  for i in S[1:-1]:
    if t[-1] == "S":
      if i == "o": t+=t[-2]
      else: t += "S" if t[-2] == "W" else "W"
    else:
      if i == "x": t += t[-2]
      else: t += "S" if t[-2] == "W" else "W"

    if t[0] == "S":
      if S[0] == "o": f = t[-1] == t[1]
      else: f = t[-1] != t[1]
    else:
      if S[0] == "x": f = t[-1] == t[1]
      else: f = t[-1] != t[1]
 
    if t[-1] == "S":
      if S[-1] == "o": g = t[-2] == t[0]
      else: g = t[-2] != t[0]
    else:
      if S[-1] == "x": g = t[-2] == t[0]
      else: g = t[-2] != t[0]
 
  if f and g:
    print(t)
    exit()

print(-1)

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

int main() {
  vector<int> vec(3);
  for (int i = 0; i < 3; i++) {
  cin >> vec.at(i);
}

  sort(vec.begin(), vec.end());
  
  if(vec.at(2)==vec.at(0)+vec.at(1)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end());
    deque<ll> pre,q1,q2;
    for(int i=0;i<n;i++){
        pre.push_back(a[i]);
    }
    q1.push_back(pre.front()); pre.pop_front();
    while(!pre.empty()){
        q1.push_front(pre.back()); pre.pop_back();
        if(!pre.empty()){
            q1.push_back(pre.back()); pre.pop_back();
        }
        if(!pre.empty()){
            q1.push_front(pre.front()); pre.pop_front();
        }
        if(!pre.empty()){
            q1.push_back(pre.front()); pre.pop_front();
        }
    }
    for(int i=0;i<n;i++){
        pre.push_back(a[i]);
    }
    q2.push_back(pre.back()); pre.pop_back();
    while(!pre.empty()){
        q2.push_front(pre.front()); pre.pop_front();
        if(!pre.empty()){
            q2.push_back(pre.front()); pre.pop_front();
        }
        if(!pre.empty()){
            q2.push_front(pre.back()); pre.pop_back();
        }
        if(!pre.empty()){
            q2.push_back(pre.back()); pre.pop_back();
        }
    }
    ll sum=0,res=0;
    ll p=q1.front(); q1.pop_front();
    while(!q1.empty()){
        sum += abs(q1.front()-p);
        p = q1.front(); q1.pop_front();
    }
    res=sum; sum=0;
    p = q2.front(); q2.pop_front();
    while(!q2.empty()){
        sum += abs(q2.front()-p);
        p = q2.front(); q2.pop_front();
    }
    cout<<max(sum,res)<<endl;
}


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

const int INF = 0x3f3f3f3f;
const int MAXN = ( int ) 1e5;

int N;
int A[ MAXN ];
int dp[ MAXN + 1 ][ 2 ];

signed main(){
  ios::sync_with_stdio( 0 );
  cin >> N;
  for( int i = 0; i < N; ++i ){
    cin >> A[ i ];
  }
  memset( dp, INF, sizeof( dp ) );
  dp[ 1 ][ 0 ] = dp[ 1 ][ 1 ] = 1;
  for( int i = 1; i < N; ++i ){
    dp[ i + 1 ][ 0 ] = min( dp[ i ][ 0 ], dp[ i ][ 1 ] ) + 1;
    dp[ i + 1 ][ 1 ] = min( dp[ i ][ 0 ], dp[ i ][ 1 ] ) + 1;
    if( A[ i - 1 ] <= A[ i ] ){
      dp[ i + 1 ][ 0 ] = min( dp[ i + 1 ][ 0 ], dp[ i ][ 0 ] );
    }
    if( A[ i - 1 ] >= A[ i ] ){
      dp[ i + 1 ][ 1 ] = min( dp[ i + 1 ][ 1 ], dp[ i ][ 1 ] );
    }
  }
  cout << min( dp[ N ][ 0 ], dp[ N ][ 1 ] ) << endl;
  return 0;
}


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

ll extGCD(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    ll g = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return g;
}

ll MOD = 1000000007;

vector<ll> mfact(1,1);

ll minv(ll a){
    ll x;ll y;
    extGCD(a, MOD, x, y);
    if(x<0){
        x+= ((-x)/MOD+1)*MOD;
        x %= MOD;
    }
    return x;
}

ll mpow(ll a,ll b){
    ll res = 1;
    while(b > 0){
        if(b%2==1)res=(res*a)%MOD;
        b/=2;
        a = (a*a)%MOD;
    }
    return res;
}

ll mfactorial(ll a){
    if(mfact.size()-1 >= a)return mfact[a];
    for(ll i = mfact.size();i<=a;i++){
        mfact.push_back((i * mfact[i-1])%MOD);
    }
    return mfact[a];
}

ll mcomb(ll n, ll r){
    return (((mfactorial(n) * minv(mfactorial(r)))%MOD) * minv(mfactorial(n-r)))%MOD;
}

int main(){
    int N;cin>>N;
    string S;cin>>S;
    ll X_1 = 0;
    ll X = 0;
    ll X_2 = 0;
    int pX = 0;
    // if(N == 1 && S[0] == '1'){
    //     cout<<0<<endl;
    //     return 0;
    // }
    for(int i = 0;i < N;i++){
        if(S[i] == '1'){
            pX++;
        }
    }
    for(int i = 0;i < N;i++){
        if(S[i] == '0')continue;
        MOD = pX;
        X += mpow(2,N-i-1);
        X %= pX;
        MOD = pX+1;
        X_2 += mpow(2,N-i-1);
        X_2 %= pX+1;
        if(pX <= 1)continue;
        MOD = pX-1;
        X_1 += mpow(2,N-i-1);
        X_1 %= pX-1;
        
    }
    for(int i = 0;i < N;i++){
        ll x = 0;
        if(S[i] == '0'){
            MOD = pX+1;
            ll n = mpow(2,N-i-1);
            // cout<<X_2<<endl;
            x = (X_2 + n) % MOD;
        }else{
            if(pX == 1){
                cout<<0<<endl;
                continue;
            }
            MOD = pX-1;
            ll n = mpow(2,N-i-1);
            // cout<<n<<endl;cout<<"!"<<endl;
            // cout<<X_1<<endl;
            x = (X_1 - n+MOD) % MOD;
        }
        // cout<<x<<endl;
        // cout<<"A"<<endl;
        int res = 1;
        while(x != 0){
            ll xx = x;
            int d = 0;
            for(d = 0;xx > 1;xx/=2){d++;}
            d+=1;
            int pop = 0;
            for(int i =0;i < d;i++){
                // cout<<i<<endl;
                if(((x>>i )& 1) == 1)pop++;
            }
            x %= pop;
            // cout<<x<<endl;
            res++;
        }
        cout<<res<<endl;
        // cout<<"---"<<endl;

    }
    
}

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

int main(){
    int r, c, i, j, x, y, land = 0;
    int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
    pair<int, int> tem, g;
    queue<pair<int, int>> q;
    cin >> r >> c;
    g = make_pair(r-1, c-1);
    string mp[r];
    for(i=0; i<r; i++){
        cin >> mp[i];
    }
    int d[r][c];
    for(i=0; i<r; i++){
        for(j=0; j<c; j++){
            d[i][j] = -1;
            if(mp[i][j] == '#') land++;
        }
    }
    d[0][0] = 0;
    q.push(make_pair(0, 0));
    while(!q.empty()){
        tem = q.front();
        q.pop();
        if(tem == g){
            break;
        }
        for(i=0; i<4; i++){
            y = tem.first+dy[i];
            x = tem.second+dx[i];
            if(0 <= y && y < r && 0 <= x && x < c && mp[y][x] == '.' && d[y][x] == -1){
                q.push(make_pair(y, x));
                d[y][x] = d[tem.first][tem.second] + 1;
            }
        }
    }
    if(d[r-1][c-1] == -1){
        cout << "-1";
    }else{
        cout << r*c - land - d[r-1][c-1] - 1;
    }
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <list>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define xx first
#define yy second
#define $1 first
#define $2 second

void solveCase() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll mn = 1e18 + 1;
	ll n, k; cin >> n >> k;
	mn = min(n, mn);
	if (n < k) {
		mn = min(mn,min(abs(k - n), abs(n)));
	}
	else {
		n = n%k;
		mn = min(mn, min(abs(k - n), abs(n)));
	}
	cout << mn;
}

int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	solveCase();
}

Measured memory_bytes: 256
s = input()

r = "AKIHABARA"
r2 = "KIHBR"
ans = "YES"
if not 5 <= len(s) <= len(r):
    ans = "NO"
if "AA" in s:
    ans = "NO"
if not "KIH" in s:
    ans = "NO"
else:
    rem_A = ""
    for c in s:
        if c != "A":
            rem_A += c
    if not rem_A == r2:
        ans = "NO"
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ull N, M;
    cin >> N >> M;
    ull ura;
    if (N>=2 && M>=2){
        ura  = (N-2) * (M-2);
    } else if (N == 1 && M >= 2){
        ura = M-2;
    } else if (M==1 && N>= 2){
        ura = N-2;
    } else{
        ura = 1;
    }
    cout << ura << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<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; }
 
 
 
 
int main(){
 
    lli h,w,k;
    cin>>h>>w>>k;
 
    lli sx,sy,ex,ey;
    cin>>sy>>sx>>ey>>ex;
    sx--,sy--,ex--,ey--;
 
    vector<vector<lli>> d(h,vector<lli>(w));    
    vector<vector<lli>> dd(h,vector<lli>(w));
 
 
    REP(i,0,h)REP(j,0,w){
        char tmp;
        cin>>tmp;
        if(tmp=='@')d[i][j]=1;
        else d[i][j]=0;
        dd[i][j]=-1;
    }
 
    queue<lli> qx,qy;
    qx.push(sx);
    qy.push(sy);
    dd[sy][sx]=0;
 
    while(qx.size()){
        lli topX = qx.front();
        lli topY = qy.front();
        LOG3(topX,topY,dd[topY][topX]);
        qx.pop(),qy.pop();
        
        lli dx[4]={-1,0,1,0};
        lli dy[4]={0,1,0,-1};
        REP(i,0,4){
            REP(K,1,k+1){
                lli nx = topX + dx[i]*K;
                lli ny = topY + dy[i]*K;
                LOG2(nx,ny);
                if(nx < 0 || w<=nx || ny<0 || h<=ny)break;
                if(d[ny][nx]==1)break;
                if(dd[ny][nx]!=-1 && dd[ny][nx]<dd[topY][topX]+1)break;
                if(dd[ny][nx]!=-1)continue;
                qx.push(nx);
                qy.push(ny);
                dd[ny][nx] = dd[topY][topX]+1;
            }
        }
    }
    LOG2(ey,ex);
    if(dd[ey][ex]==-1){
        cout<<-1<<endl;
    }
    else{
        cout<<dd[ey][ex]<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 26696
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){

  int h,w;
  cin >> h >> w;

  int rote[51][51] = {0};
  char c;
  for( int i = 1 ; i <= h ; i++ ){
    for( int j = 1 ; j <= w ; j++ ){
      cin >> c;
      rote[i][j] = c - '0';
    }
  }

  for( int i = 1 ; i <= h ; i++ ){
    for( int j = 1 ; j <= w ; j++ ){
      if( i == 1 ){
	rote[i][j] += rote[i][j - 1];
      }else if( j == 1 ){
	rote[i][j] += rote[i - 1][j];
      }else{
	rote[i][j] += min(rote[i - 1][j], rote[i][j - 1]);
      }
    }
  }
  cout << rote[h][w] << endl;
  return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

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

    ll d = c - a - b;
    if (d > 0 && 4 * a * b < d * d) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
def compress(s):
    z = []
    cont = 1
    for ca, cb in zip(s, s[1:]):
        if ca == cb:
            cont += 1
        else:
            z.append(cont)
            cont = 1
    z.append(cont)
    # print(z)
    return z


def main():
    s = input()
    n = len(s)
    k = int(input())

    z1 = compress(s)
    if len(z1) == 1:
        # like 'aaa'
        return n * k // 2

    k1 = sum(map(lambda x: x // 2, z1))
    if s[0] != s[-1]:
        # like 'ab'
        return k1 * k
    else:
        # like 'aba' / 'abaa'
        z2 = compress(s * 2)
        k2 = sum(map(lambda x: x // 2, z2))
        d = k2 - k1
        return k1 + d * (k - 1)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
using namespace std;
int K,N,A[200005],mx;
int main() {
    scanf("%d%d",&K,&N); for (int i = 0;i < N;i++) scanf("%d",&A[i]);
    mx = A[0] + K - A[N - 1]; for (int i = 1;i < N;i++) mx = max(mx,A[i] - A[i - 1]);
    printf("%d\n",K - mx);
}


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

using namespace std;

int main ()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b)
    {
        swap(a,b);
    }
    if(a>c)
    {
        swap(a,c);
    }
    if(b>c)
    {
        swap(b,c);
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}


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

int main() {
	
	//vector<int> a(n);  sort(a.begin(),a.end());
	//cout << "test" << endl;

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	//string ans="YES";


	int n;
	cin >> n;
	
	vector<int> a(n);
	vector<int> b(n-1);
	
	
	rep(i,n-1) cin >> b[i];
	
	int memo;
	int ans=b[0];
	
	for(int i=1;i<n-1;i++) ans+=min(b[i],b[i-1]);
	
	ans+=b[n-2];
	
	
	
	cout << ans << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 256
/*问题陈述
给你两个正整数a和b。设x是a和b的平均值。打印x四舍五入到最接近的整数。

约束
a和 b是整数。
1≤a，b≤100
输入
标准输入的输入格式如下：

一个 b
产量 
打印x四舍五入到最接近的整数。

示例输入1
复制 
1 3
示例输出1 
复制
2
1和3的平均值为2.0，并将四舍五入到最接近的整数2。 

示例输入2
复制 
7 4
示例输出2
复制
6
7和4的平均值是5.5，并将四舍五入到最接近的整数6。 
示例输入3
复制 
5 5
示例输出3
复制 
五
*/
#include <iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int x;
    int  j;
	j=a+b;
	if(j%2>0.4)
	{
		x=j/2+1;
		cout<<x;
		return 0;
	}
	else
	{
	 	x=j/2;
		cout<<x;
		return 0;	
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int a, b;
    cin >> a >> b;

    int ans = INF;
    rep(i, 1100) {
        double va = (double)i * 0.08;
        double vb = (double)i * 0.1;
        if (a == (int)va && b == (int)vb) {
            ans = i;
            break;
        }
    }

    if (ans == INF) puts("-1");
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

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

	if (0 == (B + A) % 2){
		printf("%d", (B + A) / 2);
	}
	else{
		printf("IMPOSSIBLE");
	}

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int ans = 0;

		for(int i = 0; i <= A; i++) {
			if(500 * i > X) {
				break;
			}
			for(int j = 0; j <= B; j++) {
				if(500 * i + 100 * j > X) {
					break;
				}
				for(int k = 0; k <= C; k++) {
					if(500 * i + 100 * j + 50 * k == X) {
						ans++;
					}else if(500 * i + 100 * j + 50 * k > X) {
						break;
					}
				}
			}
		}

		System.out.println(ans);
	}

}


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

int main(){
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if(s[0] == s[1] and s[1] != s[2] and s[2] == s[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> data(N+1,vector<int>(3));
  data.at(0) = {0,0,0};
  for(int i = 1;i<N+1;i++){
    cin >> data.at(i).at(0);
    cin >> data.at(i).at(1);
    cin >> data.at(i).at(2);
//    cout << data.at(i).at(0) << data.at(i).at(1) << data.at(i).at(2) << endl;
  }

  string res = "Yes";
  
	for(int i = 1;i < N+1; i++){
//      cout << i << endl;
      int diff = 0;
      diff += abs(data.at(i).at(1) - data.at(i-1).at(1));
      diff += abs(data.at(i).at(2) - data.at(i-1).at(2));
      int step = 0;
      step = (data.at(i).at(0) - data.at(i-1).at(0)) - diff;
//      cout << "diff:" << diff << " step:" << step << endl;
      if((step >= 0) && (step%2 == 0)){
        res = "Yes";
      }
      else{
        res = "No";
        break;
      }
    }
  
  cout << res << endl;
}




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

int n, a[100009], b[100009], c[300009];

int main(){
	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>a[i]>>b[i];
		c[a[i]+b[i]]++;
	}
	for(int i=0;i<=250000;i++){
		c[i+1]+=(c[i]/2);
		c[i]%=2;
	}
	for(int i=0;i<=250000;i++){
		if(c[i]>=1) cout<<i<<" "<<0<<endl;
	}
	return 0;
}


Measured memory_bytes: 4860
from collections import Counter
N = int(input())
S = input()
m = Counter(S)
cnt_set = 0
cur = 0
for x in S:
    if x == '(':
        cur += 1
    else:
        if cur > 0:
            cnt_set += 1
            cur -= 1
ans = '('*(m[')']-cnt_set) + S + ')'*(m['(']-cnt_set)
print(ans)

Measured memory_bytes: 3316
// 解説AC
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int a[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    int ans = n;
    vector<bool> used(m, 0);
    for(int s = 0; s+1 < m; s++){
        vector<int> cnt(m, 0);
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(used[a[i][j]])   continue;
                cnt[a[i][j]]++;
                break;
            }
        }
        int ma = 0, ind = -1;
        for(int i = 0; i < m; i++){
            if(cnt[i] > ma){
                ma = cnt[i];
                ind = i;
            }
        }
        ans = min(ans, ma);
        used[ind] = true;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(i%2==0 && s[i]=='p')ans--;
        if(i%2==1 && s[i]=='g')ans++;
    }
    cout<<ans<<endl;
}

   


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)









 
int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    REP(i, n){
        cin >> a[i];
    }
    REP(i, n){
        cin >> f[i];
    }
    sort(a.begin(), a.end());
    sort(f.begin(), f.end());
    ll l = -1, r = INF;
    while(r - l > 1){
        ll s = (l + r) / 2;
        ll cnt = 0;
        REP(i, n){
            if(a[i] * f[n - 1 - i] > s){
                ll tmp = a[i] * f[n - 1 - i] - s;
                if(tmp % f[n - 1 - i] == 0){
                    cnt += tmp / f[n - 1 - i];
                }
                else{
                    cnt += tmp / f[n - 1 - i] + 1;
                }
            }
        }
        if(cnt <= k){
            r = s;
        }
        else{
            l = s;
        }
    }
    cout << r << endl;
}

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

using namespace std;

int main() {
    string n; cin >> n;
    for(int i = 0; i<n.size(); i++){
        if (n[i] == '1'){
            cout << '9';
        }else {
            cout << '1';
        }
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=500;
vector<int> G[maxn];
int dfn[maxn],low[maxn];
int n,m,u,v,dep,ans;

void init()
{
    dep=ans=0;
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    for(int i=0;i<=n;i++) G[i].clear();
}

void Tarjan(int u,int fa)
{
    dfn[u]=low[u]=++dep;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i];
        if(!dfn[v]){
            Tarjan(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]) ans++;
        }else if(v!=fa)
            low[u]=min(low[u],dfn[v]);
    }
}

int main()
{
    while(cin>>n>>m)
    {
        init();
        for(int i=0;i<m;i++){
            cin>>u>>v;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        Tarjan(1,-1);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int fact[210000], fact_R[210000];

long long int pow_m1(long long int num){
	long long int pow_num = MOD - 2;
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

long long int DP[3100] = {};

int main(){
	
	fact[0] = 1;
	fact_R[0] = 1;
	
	for(int i = 1; i < 210000; i++){
		fact[i] = (fact[i - 1] * i) % MOD;
		fact_R[i] = (fact_R[i - 1] * pow_m1(i)) % MOD;
	}
	
	long long int H, W, N;
	cin >> H >> W >> N;
	
	P p[3100] = {};
	
	for(int i = 1; i <= N; i++){
		cin >> p[i].first >> p[i].second;
	}
	p[0].first = 1;
	p[0].second = 1;
	p[N + 1].first = H;
	p[N + 1].second = W;
	
	sort(p, p + (N + 2));
	
	DP[0] = MOD - 1;
	
	for(int i = 1; i <= N + 1; i++){
		for(int j = 0; j < i; j++){
			if(p[j].first <= p[i].first && p[j].second <= p[i].second){
				long long int d1 = p[i].first - p[j].first;
				long long int d2 = p[i].second - p[j].second;
				long long int num = DP[j];
				num *= fact[d1 + d2];
				num %= MOD;
				num *= fact_R[d1];
				num %= MOD;
				num *= fact_R[d2];
				num %= MOD;
				DP[i] += num;
				DP[i] %= MOD;
			}
		}
		DP[i] = MOD - DP[i];
		DP[i] %= MOD;
	}
	
	cout << DP[N + 1] << endl;
	
	return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
using namespace std;
int mat[1005][1005],vis[1005][1005];
string s[1005];
int h,w,sx,sy,dx,dy;
priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> pq;
bool check(int x,int y){
    if(x<0||x>h||y<0||y>w||s[x][y]=='#')
        return false;
    return true;
}
void func(int x1,int y1,int x,int y,int d){
    if(mat[x1][y1]>mat[x][y]+d){
        mat[x1][y1] = mat[x][y] + d;
        pq.push({mat[x1][y1],{x1,y1}});
    }
}
int32_t main()
{
    IOS;
    
    cin >> h >> w >> sx >> sy >> dx >> dy;
    sx--,sy--,dx--,dy--;
    
    for(int i = 0;i < h; i++)
        cin >> s[i];
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w; j++){
            mat[i][j] = INT_MAX;
        }
    }
    mat[sx][sy] = 0;
    pq.push({0,{sx,sy}});
    while(!pq.empty()){
        auto x = pq.top();
        int d = x.first;
        int x1 = x.second.first;
        int y1 = x.second.second;
        pq.pop();
        if(vis[x1][y1]==1)
            continue;
        vis[x1][y1] = 1;
        if(!check(x1,y1))
            continue;
        for(int i = -2;i <= 2; i++){
            for(int j = -2;j <=2 ; j++){
                if(i==0&&j==0)
                    continue;
                int xc = x1 + i;
                int yc = y1 + j;
                if(check(xc,yc)){
                    if(abs(i)+abs(j)==1)
                        func(xc,yc,x1,y1,0);
                    else
                        func(xc,yc,x1,y1,1);
                }
            }
        }   
    }
    // for(int i = 0;i < h;i++){
    //     for(int j = 0;j < w; j++){
    //         cout << mat[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    if(mat[dx][dy]==INT_MAX){
        cout << "-1" << "\n";
    }else
    {
        cout << mat[dx][dy] << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 20516