akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

/*
    1-indexed であることに注意 !!
*/
template <typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n) : n(n), dat(n + 1, 0) {}

    T sum(int a) {
        T res = 0;
        for (int i = a; i > 0; i -= (i & (-i))) res += dat[i];
        return res;
    }

    T sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }

    void add(int k, T x) {
        if (k == 0) return;
        for (int i = k; i <= n; i += (i & (-i))) dat[i] += x;
    }

    /*
        a[0] + a[1] + ... + a[res] >= x
    */
    int lower_bound(T x) {
        if (x <= 0) return T(0);
        int res = 0, k = 1;
        while (k < n) k <<= 1;
        for (; k > 0; k >>= 1) {
            if (res + k <= n && dat[res + k] < x) {
                x -= dat[res + k];
                res += k;
            }
        }
        return res + 1;
    }
};

signed main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
    }
    auto isOK = [&](ll x) {
        int sum[n + 1] = {};
        rep(i, n) {
            sum[i] = (a[i] >= x ? 1 : -1);
        }
        rep(i, n) {
            sum[i + 1] += sum[i];
        }
        ll cnt = 0;
        BIT<int> bit(2 * n);
        bit.add(n + 0, 1);
        rep(i, n) {
            cnt += bit.sum(n + sum[i]);
            bit.add(n + sum[i], 1);
        }
        return cnt >= ((ll)n * (n + 1) / 2 + 1) / 2;
    };
    ll ok = 0, ng = INF + 1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (isOK(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, s;
    cin >> n >> s;
    vector<mint> dp(s+1);
    dp[0] = 1;
    rep(i, n) {
        int a;
        cin >> a;
        vector<mint> p(s+1);
        swap(dp, p);
        rep(j, s+1) {
            dp[j] += p[j] * 2;
            if (j+a <= s) dp[j+a] += p[j];
        }
    }
    cout << dp[s] << endl;
}



Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
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()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N, K;
    cin >> N >> K;
    vec2 G(N);
    rep(i, N - 1){
        ll a, b;
        cin >> a >> b;
        --a, --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    vec visit(N, 0);
    vec ct(N, 0);
    ll ans = 1;
    stack<ll> sk;

    sk.push(0);
    while(!sk.empty()){
        ll now = sk.top();
        sk.pop();
        if(visit[now]) continue;

        ll check = 0;
        for(auto v : G[now]) check += ct[v], ++ct[v], sk.push(v);
        ans *= max(K - check, 0LL);
        ans %= MOD;
        ++ct[now];
        ++visit[now];
    }

    print(ans);

    return 0;
}

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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;

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

    cout << ans << endl;
}

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

using namespace std;

#define PB push_back
#define SZ(a) (int)a.size()
#define MP make_pair

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;

int a[10][10];

int main() {

	int N;
	scanf("%d", &N);

	for(int i = 1; i <= N; i++) {
		int last = i % 10;
		int first = i;
		while(first / 10 > 0) first /= 10;
		a[first][last]++;
	}

	int ans = 0;

	for(int i = 1; i <= 9; i++) {
		for(int j = 1; j <= 9; j++) {
			ans += a[i][j] * a[j][i];
		}
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
N = int(input())
X = [int(_) for _ in input().split()]
max = 0
min = 100
for i in X:
    if max < i:
        max = i
    if min > i:
        min = i

ans = 0
for p in range(max-min):
    total = 0
    for i in X:
        total += (i-p) ** 2
    if ans == 0:
        ans = total
    if ans > total:
        ans = total
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

ll solve(ll w,ll a,ll b){
    int res;
    int c = min(a,b);
    int d = max(a,b);
    c += w;
    res = d-c<0 ? 0:d-c;
    return res;
}

int main(){
    int n;cin>>n;
    ll ans;
    fore(i,1,100000){
        n-=i;
        if(n<=0){
            ans = i;
            break;
        }
    }
    cout<<ans;
	return 0;
}

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

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

const int VERY_LARGE_NUM = 1e6;
vector<pair<int, int>> G[VERY_LARGE_NUM];

void dijkstra(int start_node_id, vector<int>& color, vector<int>& d) {
  d[start_node_id] = 0;
  color[start_node_id] = 1;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      PQ;
  PQ.push(make_pair(start_node_id, 0));
  while (!PQ.empty()) {
    pair<int, int> min_node = PQ.top();
    PQ.pop();
    int u = min_node.second;
    color[u] = 2;
    if (d[u] < min_node.first) continue;
    for (int i = 0; i < G[u].size(); i++) {
      int node_id = G[u][i].second;
      int weight = G[u][i].first;
      if (color[node_id] != 2) {
        if (d[node_id] > d[u] + weight) {
          d[node_id] = d[u] + weight;
          color[node_id] = 1;
          PQ.push(make_pair(d[node_id], node_id));
        }
      }
    }
  }
}

int main() {
  int n, u, k, c, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      G[u].push_back(make_pair(c, v));
    }
  }
  debug(G);
  vector<int> color(n);
  vector<int> d(n, VERY_LARGE_NUM);
  dijkstra(0, color, d);
  for (int i = 0; i < n; i++) {
    cout << i << ' ' << d[i] << endl;
  }
  return 0;
}



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

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

Measured memory_bytes: 4052
#include <iostream>

#include <bits/stdc++.h>


//author 16301122

using namespace std;

int main() {
	
    int p,q,r;
    int t=0;
    int c=1;
    cin>>p>>q;
 while(p-->0){
 	
    cin>>r;
    t=t+r;
    if(t<=q){
 	
 	c++;
 }
 }
 cout<<c<<endl;
 return 0;
 }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
class dice{
  char face[6];
public:
  dice(){for(char i=0;i<6;++i)face[i]=i+1;}
  char top(){return face[0];}
#define decl(a,b,c,d,e,f) char temp[6]={face[a-1],face[b-1],face[c-1],face[d-1],face[e-1],face[f-1]}
#define impl(x,a,b,c,d,e,f) void x(){decl(a,b,c,d,e,f);std::copy(temp,temp+6,face);}
  impl(North,2,6,3,4,1,5)
  impl(East,4,2,1,6,5,3)
  impl(West,3,2,6,1,5,4)
  impl(South,5,1,3,4,6,2)
  impl(Right,1,3,5,2,4,6)
  impl(Left,1,4,2,5,3,6)
};
int main(){
  int n;
  while(1){
    std::cin>>n;
	if(!n)return 0;
	dice d;
	int sum=1;
#define op(x) if(str==#x){d.x();sum+=d.top();continue;}
	while(n--){std::string str;std::cin>>str;op(North)op(East)op(West)op(South)op(Right)op(Left)}
	std::cout<<sum<<std::endl;
  }
}

Measured memory_bytes: 0
N = int(input())
for _ in range(N):
	A = []
	x, y, b, p = map(int, input().split())
	s = x*b+y*p  #全部バラ
	A.append(int(s))
	wari = 0.8*(5*x+2*y)
	for i in range(1, 4):
		s = wari*i
		if b-(5*i)>0:
			s += 0.8*(b-(5*i))*x
		if p-(2*i)>0:
			s += 0.8*(p-(2*i))*y
		A.append(int(s))
	print(min(A))


Measured memory_bytes: 5616
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >>s;
  int count = 0;
  for(int i = 0; i < 4;i++){
    for(int j = 0; j < 4; j++){
      if(s[i] == s[j])count++;
    }
  }
  if(count == 8)cout << "Yes";
    else cout <<"No";
}


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

#define long long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,v) memset(a,v,sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define INF 0x3f3f3f3f//infinity for integers
#define JJ ios_base::sync_with_stdio(0); cin.tie(0)//input fast
#define MOD 1000000007
#define hash(n) unordered_map<int,int>mp(n)

 
int main() 
{ 
	JJ;
    int n; cin>>n;
    int arr[n];
    int x=0;
    FOR(i,0,n){
    	cin>>arr[i];
    	x^=arr[i];
    }
    FOR(i,0,n){
    	cout<<(x^arr[i])<<" ";
    }


    
} 

Measured memory_bytes: 4392
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);



int main(){
  FAST_IO
  int N, min = INF; cin >> N;

  for(int rep = 0; rep < N; ++rep){
    int cur = 0, x; cin >> x;
    while((x & 1) == 0){
      cur++;
      x >>= 1;
    }
    min_self(min, cur);
  }

  cout << min << "\n";
 
  return 0;
}


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

#define rep(i,a) for(int i=0;i<(a);++i)

int main()
{
    int L, M, N, sum;
    while(cin >> L && L) {
        bool ok = false;
        sum = 0;
        rep(i, 12) {
            cin >> M >> N;
            sum += M - N;
            if(!ok && sum >= L) {
                cout << i + 1 << endl;
                ok = true;
            }
        }
        if(!ok) 
            cout << "NA" << endl;
    }
}

Measured memory_bytes: 0
blue_num = int(input())
blue_list = []
[blue_list.append(input()) for i in range(blue_num)]
red_num = int(input())
red_list = []
[red_list.append(input()) for n in range(red_num)]

count_list = []
for i in blue_list:
    count = 0
    count += blue_list.count(i)
    for j in red_list:
        if i == j:
            count -= 1
        else:
            pass
    count_list.append(count)


if max(count_list) <= 0:
    print(0)
else:
    print(max(count_list))



Measured memory_bytes: 3064
from scipy.special import comb

N = int(input())
sdict = {}
for i in range(N):
    inp = ''.join(sorted(list(input())))
    if inp not in sdict:
        sdict.update({inp:1})
    else:
        sdict[inp] += 1

ans = 0
for key in sdict:
    ans += comb(sdict[key], 2 , exact=True)

print(ans)


Measured memory_bytes: 55108
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    const double a = 380000;
    double ans = 0;
    rep(i, n) {
        double x;
        string s;
        cin >> x >> s;
        if(s == "BTC") {
            ans += a*x;
        }
        else {
            ans += x;
        }
    }
    
    exout(ans);
    re0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  long long int A, B, C;
  scanf("%lld %lld %lld", &A, &B, &C);
  if(((A * B) <= (B * C)) && ((A * B) <= (A * C))){
    switch(C % 2){
      case 0:
        printf("0\n");
        return 0;
      case 1:
        printf("%lld\n", A*B);
        return 0;
    }
  }
  else if(((A * C) <= (B * C)) && ((A * C) <= (A * B))){
    switch(B % 2){
      case 0:
        printf("0\n");
        return 0;
      case 1:
        printf("%lld\n", A*C);
        return 0;
    }
  }
  else{
    switch(A % 2){
      case 0:
        printf("0\n");
        return 0;
      case 1:
        printf("%lld\n", B*C);
        return 0;
    }
  }
}

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

int main(){
    int64_t mod = 1000000007;
    int64_t n, k; cin >> n >> k;
    vector<vector<int64_t>>c(n+1,vector<int64_t>(n+1,0));
    rep(i,n+1) c[i][0] = 1;
    for(int64_t i = 1; i < n+1; i++){
        for(int64_t j = 1; j < n+1; j++){
            c[i][j] = c[i-1][j-1]+c[i-1][j];
            c[i][j] %= mod;
        }
    }
    for(int64_t i = 1; i <= k; i++){
        int64_t ans = c[n-k+1][i]*c[k-1][i-1];
        ans %= mod;
        cout << ans << endl;
    }
}

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


def main():
    N = int(input())
    work = []  # due, duration
    for _ in range(N):
        a, b = map(int, input().split())
        work.append((b, -a))
    work.sort()

    now = 0
    for b, a in work:
        now = now - a
        if now > b:
            return "No"
    return "Yes"


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

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

int main(int argc, char const *argv[])
{
	ll n, m; cin >> n >> m;
	if (n > m) swap(n, m);
	if (n == 1 and m == 1) {
		cout << 1 << endl;
	} else if (n == 1) {
		cout << m - 2 << endl;
	} else {
		cout << (n - 2) * (m - 2) << endl;
	}
	return 0;
}


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

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for(ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for(ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define MOD 10000007 
#define MAXR 100000 

int N, M; ll X;
ll C[12];
ll A[12][12];
ll ans = INF;

signed main() {
    cin >> N >> M >> X;
    REP(i, N) {
        cin >> C[i];
        REP(j, M) cin >> A[i][j];
    }

    for (int bit = 0; bit < (1 << N); bit++) {
        bitset<12> combo(bit);
        ll point[12] = {0};
        ll cost = 0;
        for (int i = 0; i < N; i++) {
            if(combo.test(i) != 1) continue;
            cost += C[i];
            REP(j, M) point[j] += A[i][j];
        }
        bool flag = true;
        REP(j, M) if(point[j] < X) flag = false;
        if (flag) ans = min(ans, cost);
    }

    cout << ((ans == INF) ? -1 : ans) << endl;
}

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

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

    int N; cin >> N;
    int H[N]; for(int i=0;i<N;i++) cin >> H[i];

    int counter = 0;
    bool flag = true;

    for(int i=0;i<N;i++){
        flag = true;
        for(int j=0;j<i;j++){
            if(H[j]>H[i]){
                flag = false;
                break;
            }
        }
        if(flag) counter++;
    }

    cout << counter;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
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;}
constexpr long long INF = 1e18,MOD = 1000000007;

void pr(bool f){
	if(f)cout<<"Yay!"<<endl;
	else cout<<":("<<endl;
}



signed main(){
	int N;
	cin>>N;
	vector<int>cnt(N+1,0);
	int ans = 1;
	cnt[0]=3;
	REP(i,N){
		int t;
		cin>>t;
		t+=1;
		(ans*=cnt[t-1])%=MOD;
		cnt[t]++;
		cnt[t-1]--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1152
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
n, k = map(int, raw_input().split())

# 文字列の入力
str = list(raw_input())

str[k-1] = str[k-1].lower()
# 出力
newstr = "".join(str)
print(newstr)

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

int main() {
  int n, i, ans = 0;
  cin >> n;
  vector<int> p(n);
  for (i = 0; i < n; ++i) {
    cin >> p[i];
  }
  sort(p.rbegin(), p.rend());
  for (i = 0; i < n; ++i) {
    if (i == 0) {
      ans += p[i] / 2;
    } else {
      ans += p[i];
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

import math

B = sorted([a-i for i,a in enumerate(A, start=1)])

ans = []

if N%2 == 1:
    b = B[N//2]
    ans.append(sum([abs(x - b) for x in B]))
else:
    b_left = (B[N//2 - 1] + B[N//2])//2
    b_right = math.ceil((B[N//2 - 1] + B[N//2])/2)
    ans.append(sum([abs(x - b_left) for x in B]))
    ans.append(sum([abs(x - b_right) for x in B]))

print(min(ans))

Measured memory_bytes: 33240
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,n,tol,tim;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>tim>>a>>b;
		tol=a+b;
		if((tim-tol)%2==1||tim<tol){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
} 

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

int main() {
    int K, S;
    cin >> K >> S;

    int res = 0;
    for (int X = 0; X <= K; X++) {
        for (int Y = 0; Y <= K; Y++) {
            if (S - X - Y <= K && S - X - Y >= 0) {
                res++;
            }
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
x,y,xy=[],[],[]
for _ in range(n):
  a,b=map(int,input().split())
  x.append(a)
  y.append(b)
  xy.append((a,b))
x.sort()
y.sort()
ans=float('inf')
for i in range(n-1):
  x1=x[i]
  for j in range(i+1,n):
    x2=x[j]
    for l in range(n-1):
      y1=y[l]
      for m in range(l+1,n):
        y2=y[m]
        cnt=0
        for o in range(n):
          x3,y3=xy[o]
          if x1<=x3<=x2 and y1<=y3<=y2:
            cnt+=1
        if cnt>=k:
          ans=min(ans,(x2-x1)*(y2-y1))
print(ans)

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

int main(void) {
    int A,B,C,X,Y;cin>>A>>B>>C>>X>>Y;

    int total = A * X + B * Y;
    int infimum = (X >= Y) ? C * 2 * Y + A * (X - Y) : C * 2 * X + B * (Y - X);
    int muximum = 2 * C * max(X, Y);
    cout << min(min(total, infimum), muximum) << endl;
    return 0;
}

Measured memory_bytes: 888
H,W=map(int,input().split())
if H==1 or W==1:
    print(1)
else:
    if H%2==0:
      print(H*W//2)
    else:
      if W%2==0:
        print(H*W//2)
      else:
        print(H*(W-1)//2+(H+1)//2)

Measured memory_bytes: 2940
#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>;

int main() {
  long double n;
  cin >>n;
  n=2.0*n*3.141592653589;
  cout << n;
}

Measured memory_bytes: 3768
import java.util.Scanner;

class Main{
  public static void main(String args[]){
  
    Scanner stdIn = new Scanner(System.in);
    int k = stdIn.nextInt();
    
    int[] col = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
    System.out.println(col[k-1]);
  }
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;


int N, M;
VI P(1000);

int main() {
    while(std::cin >> N >> M) {
        if(N == 0 && M == 0) break;
        REP(i, N) {
            std::cin >> P[i];
        }

        std::vector<int> sum;
        sum.push_back(0);
        sum.insert(sum.end(), P.begin(), P.end());
        REP(i, N) {
            REP(j, N) {
                if(P[i] + P[j] <= M) {
                    sum.pb(P[i] + P[j]);
                }
            }
        }

        UNIQUE(sum);

        int res = 0;
        for(auto x: sum) {
            auto py = std::upper_bound(ALL(sum), M-x) - 1;
            res = std::max(res, x + *py);
        }
        std::cout << res << std::endl;
    }
}


Measured memory_bytes: 10688
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        
        String S=sc.next();
        String x=S.substring(0,1);
        String y=S.substring(1,2);
        String z=S.substring(2,3);
        if(x.equals(y)||y.equals(z)||z.equals(x)){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 23764
H,W = map(int,input().split())
grid = [input().split() for _ in range(H)]
check = []

for i in range(H):
    if '#' not in grid[i][0]:
        check.append(i-len(check))
for i in check:
    grid = grid[:i] + grid[i+1:]
check = []

for i in range(W):
    if all(grid[j][0][i]=='.' for j in range(len(grid))):
        check.append(i - len(check))
for i in check:
    for k in range(len(grid)):
        grid[k][0] = grid[k][0][:i] + grid[k][0][i+1:]
        
for i in grid:
    print(i[0])

Measured memory_bytes: 67496
#include<iostream>
#include<queue>
#include<bitset>
#include<algorithm>
#include<climits>
#include<vector>
#include<deque>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> P;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define dump(a) rep(i,a.size()){ cout<<a[i]<<" "; } cout<<endl;
#define dumparr(a,n) rep(i,n){ cout<<a[i]<<" "; } cout<<endl;
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define FINF DBL_MAX/3
#define EPS 1e-7
#define OUT1(n1) cout<<n1<<endl
#define OUT2(n1,n2) cout<<n1<<" "<<n2<<endl
#define OUT3(n1,n2,n3) cout<<n1<<" "<<n2<<" "<<n3<<endl
#define OUT4(n1,n2,n3,n4) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<endl
#define OUT5(n1,n2,n3,n4,n5) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<endl
#define OUT6(n1,n2,n3,n4,n5,n6) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<" "<<n6<<endl
#define OUT(n, ...) OUT##n(__VA_ARGS__)

/* slide動作をする回数=kとして固定する。
 * 区間内の最小値、RMQにしてもいいし、順序がわかってるなら漸化式を作ってといてもいい(min[i:j] = min(min[i+1:j], a[i]))
 * なぜかWAになっちゃう
 */

int main(){
  ll n,x;
  cin>>n>>x;
  ll a[2002];
  rep(i,n){
    cin>>a[i];
  }

  // 各クエリに対して最小値の集合
  ll mq[2002];
  rep(i,n) { mq[i] = a[i]; }
  ll m = 0; // 最小所要時間
  rep(i,n) m += a[i];
  rep(k,n){
    // k回スライド動作をする
    ll s = 0;
    rep(i,n) {
      // iを作れる最小の費用
      mq[i] = mmin(mq[i], a[(i-k)%n >= 0 ? (i-k)%n : (i-k)%n + n]);
      s += mq[i]; // a[i-k],...,a[i]の中の最小値 = min(a[i-(k-1)](=a[i-k+1]),..,a[i]の中の最小値, a[i-k])
    }
    /* dbg(k); */
    /* dumparr(mq, n); */
    m = mmin(m, k*x + s);
  }
  cout<<m<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
bool t[200010];
vector <int> e[200010];
int dfs ( int v ) {
    int y = 1;
    t[v] = true;
    for ( int i = 0 ; i < e[v].size(); i++ ) {
        int u = e[v][i];
        if ( !t[u] ){
            y += dfs(u);
        }
    }
    return y;

}
int main()
{
    int n;
    int m;
    cin >> n ;
    cin >> m;
    for ( int i = 0 ; i < m ; i++ ) {
        int a;
        int b;
        cin >> a;
        cin >> b;
        a--;
        b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    int ans = 0;
    for ( int i = 0 ; i < n ; i++ ) {
        if ( !t[i] ){
            int x = dfs(i);
            ans = max(ans, x);
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 24072
using System;
using System.Linq;

namespace _1000
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string now = Console.ReadLine();
                if (now == null)
                {
                    break;
                }
                int[] x = now.Split().Select(int.Parse).ToArray();
                Console.WriteLine(x[0] + x[1]);
            }
        }
    }
}

Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;string s;
    cin>>n>>s;
    if(s.size()>n){
        cout<<s.substr(0,n)<<"..."<<endl;
    }else puta(s);
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;
    vector <string> X(N);
    loop(i,0,N) cin >> X[i];
    vector < vector <ll> > count(N);
    loop(i,0,N) count[i].resize(26);
    loop(i,0,N) loop(j,0,26) count[i][j]=0;
    loop(i,0,N)
    {
        loop(j,0,X[i].length())
        {
            count[i][X[i][j]-'a']++;
        }
        // loop(j,0,26) count[j][tcount[j]]++;
    }
    sort(count.begin(), count.end());
    ll ans=0;
    ll same=1;
    loop(i,1,N)
    {
        if (count[i]==count[i-1]) same++;
        else 
        {
            ans+=(same)*(same-1)/2;
            same=1;
        }
    }
    ans+=(same)*(same-1)/2;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 29952
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 1e5 + 7;
int n;
LL b[N], L[N], R[N], X;
struct data {
	LL b, L, R;
}a[N];
LL calc(data x, LL now) {
	if(now <= x.b) return now * x.L;
	return x.b * x.L + (now - x.b) * x.R;
}
bool cmp(data x, data y) {
	return calc(x, X) < calc(y, X);
}
LL ggg = 0;
LL check(LL mid) {
	LL cnt = mid / X, sum = 0, ans = 0;
	rep(i, n - cnt + 1, n) sum += calc(a[i], X);
	mid %= X;
	rep(i, 1, n - cnt) Max(ans, sum + calc(a[i], mid));
	sum += calc(a[n - cnt], X);
	rep(i, n - cnt + 1, n) Max(ans, sum - calc(a[i], X) + calc(a[i], mid));
	return ans;
}
int main() {
#ifdef fwat
#endif
	n = gi(), X = gi();
	rep(i, 1, n) b[i] = gi(), L[i] = gi(), R[i] = gi(), ggg += b[i] * L[i];
	if(ggg == 0) return puts("0"), 0;
	LL l = 0, r = (LL) n * X - 1, ret = n * X;
	rep(i, 1, n) a[i] = (data){ b[i], L[i], R[i]};
	sort(a + 1, a + 1 + n, cmp);
	while(l <= r) {
		LL mid = l + r >> 1;
		if(check(mid) >= ggg) ret = mid, r = mid - 1;
		else l = mid + 1;
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> > 
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 3e5 + 5;
int row[MAX], col[MAX];
int main()
{
	boost;
	int n, m, k, i, j;
	cin >> n >> m >> k;
	    
	vector <pii> v;
	fo(i, 0, k) {
	    int x, y;
	    cin >> x >> y;
	    v.pb({x, y});
	}
	sort(all(v));
	fo(i, 0, k)
	row[v[i].f]++;
	
	fo(i, 0, k)
	col[v[i].s]++;
	
	multiset <int> op;
	foe(i, 1, m)
	op.insert(col[i]);
	
	int ans = 0;
	for(int i = 0, j = 0; i < k; i = j) {
	    int mx = -1;
	    while(j < k && v[i].f == v[j].f) {
	        op.erase(op.lower_bound(col[v[j].s]));
	        mx = max(mx, col[v[j].s]);
	        ++j;
	    }
	    
	    int curr = mx - 1;
	    if(!op.empty()) {
	        auto it = op.end();
	        --it;
	        curr = max(curr, *it);
	    }
	    curr += row[v[i].f];
	    ans = max(ans, curr);
	    
	    for(int l = i; l < j; l++)
	    op.insert(col[v[l].s]);
	}
	cout << ans;
}

Measured memory_bytes: 21856
#include <iostream>
using namespace std;
class xl {
	int row;
	int col;
	int **cells;
public:
	xl(int row,int col);
	~xl();
	void calcSum(void);
	int getCells(int r, int c);
	int setCells(int r, int c, int x);
};

int xl::getCells(int r, int c){
	return cells[r][c];
}
int xl::setCells(int r, int c, int x){
	cells[r][c] = x;
}
xl::xl(int row, int col){
	this->row = row;
	this->col = col;
	cells = new int*[row + 1];
	for(int i = 0; i < row + 1; i++){
		cells[i] = new int[col + 1];
	}
}
xl::~xl(){
	for(int i = 0; i < row + 1; i++){
		delete[] cells[i];	
	}
	delete[] cells;
}
void xl::calcSum(void){
	for(int i = 0; i < row; i++){
		int sum = 0;	
		for(int j = 0; j < col; j++){
			sum += cells[i][j];
		}
		cells[i][col] = sum;
	}
	for(int i = 0; i < col + 1; i++){
		int sum = 0;
		for(int j = 0; j < row; j++){
			sum += cells[j][i];
		}
		cells[row][i] = sum;
	}
}


int main(int argc,char *argv[]){
	int r,c;
	cin >> r >> c;
	xl *exl = new xl(r,c);
	for(int i = 0; i < r; i++){
		for(int j = 0;j < c; j++){
			int x;
			cin >> x;
			exl->setCells(i,j,x);
		}
	}
	exl->calcSum();
	for(int i = 0; i < r + 1; i++){
		for(int j = 0; j < c; j++){
			cout << exl->getCells(i,j) << " ";
		}
		cout << exl->getCells(i, c) << endl;
	}
	delete exl;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  string s;
  cin >> s;
  if (s == "ARC") {
    cout << "ABC" << endl;
  } else {
    cout << "ARC" << endl;
  }
}



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

double ru2(int a){
		if(a==0)return 1;
		return 2*ru2(a-1);
}

int compare_int(const void *a,const void *b){
		return *(int*)b-*(int*)a;
}

int main(){
		int n,i,a[51];
		scanf("%d",&n);
		for(i=0;i<n;i++)scanf("%d",&a[i]);
		qsort(a,n,sizeof(int),compare_int);
		double ans=a[n-1]/ru2(n-1);
		for(i=0;i<n-1;i++)ans+=a[i]/ru2(i+1);
		printf("%.10f\n",ans);
		return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll a, b;
    while (cin >> a >> b, a || b) {
        ll price = b - a;
        vector<ll> ans;
        ans.pb(price/1000); price %= 1000;
        ans.pb(price/500); price %= 500;
        ans.pb(price/100); price %= 100;
        reverse(ALL(ans));
        cout << ans << endl;
    }
}

Measured memory_bytes: 3128
#include<stdio.h>

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

Measured memory_bytes: 600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
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; }

int main(){
    ll X;
    cin >> X;

    int cnt = 0;
    ll now = 100;
    while(now < X){
        now = ll(now * 1.01);
        ++cnt;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3620
def is_even(num):
    return num % 2 == 0
num = int(input())
fn = list()
input = input().split(" ")
b = list()
for e in input:
  if is_even(int(e)):
    fn.append(e)
for a in fn:
  if int(a) % 3 == 0 or int(a) % 5 == 0:
    b.append("0")
  else:
    b.append("1")
if "1" in b:
  print("DENIED")
else:
  print("APPROVED")

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

using namespace std;

long long inf=1000000007;

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

	long long ans=0;

	for(int i=0;i<=999;i++){
		string t=to_string(i);
		while((int)t.size()<3){
			t="0"+t;
		}

		bool flag=false;
		int pos=0;

		for(int j=0;j<n;j++){
			pos=j;

			if(t.at(0)==s.at(j)){
				flag=true;
				break;
			}
		}

		if(!flag) continue;

		flag=false;

		for(int j=pos+1;j<n;j++){
			pos=j;

			if(t.at(1)==s.at(j)){
				flag=true;
				break;
			}
		}

		if(!flag) continue;

		for(int j=pos+1;j<n;j++){
			if(t.at(2)==s.at(j)){
				ans++;
				break;
			}
		}
	}

	cout<<ans<<endl;

	return 0;
}


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

const int N = 5005;
const int mod = 1e9 + 7;

int dp[N][N]; // total yang di tulisan sekarang, index ke berapa;
int n, m;

char str[N];

int f(int tot, int idx){

	if(idx == n){

		if(tot == m)
			return 1;
		else
			return 0;
	
	}

	int &ret = dp[tot][idx];

	if(ret != -1)
		return ret;

	ret = 0;

	// ada yang dihapus
	if(tot > 0)
		ret = (ret + 2*f(tot-1, idx+1))%mod;
	// gak ada yang dihapus
	else
		ret = (ret + f(0, idx+1));

	// pencet x
	ret = (ret + f(tot+1, idx+1))%mod;

	return ret;
}


int main(){
	memset(dp, -1, sizeof(dp));
	scanf("%d", &n);
	scanf("%s", str);

	m = strlen(str);

	printf("%d\n", f(0, 0));
}

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

ll pow(ll n){
    if(n == 1) return 1;
    else return n*pow(n-1)%1000000007;
}

int main(){
    string s ,t;
    cin >> s >> t;
    if(t.size()>s.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    int start = -1;
    bool cont = true;
    for(int i = s.size() - t.size() ;i>=0;i--){
        for(int j = 0;j<t.size();j++){
            if(s[i+j]==t[j] || s[i+j]=='?'){
                if(j==t.size()-1){
                    cont = false;
                    start = i;
                    break;
                }
            }else break;
        }if(!cont) break;
    }

    if(start<0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for(int i=0;i<s.size();i++){
        if(start <= i && i <= start + t.size() -1) cout << t[i-start];
        else if(s[i]=='?') cout <<'a' ;
        else cout << s[i];
    }
    cout << endl;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    vector<string> b(m);

    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];

    for(int i = 0; i <= n-m; i++){
        for(int j = 0; j <= n-m; j++){
            bool flag = true;
            for(int k = i; k < i+m; k++){
                for(int l = j; l < j+m; l++){
                    if(a[k][l] != b[k-i][l-j]) flag = false;
                }
            }
            if(flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
LL s[210000],a[210000];
int n;
int fd(int S,int T)//左小右大  
{
	int l=S,r=T,ret=-1;
	LL rsum=(1LL<<63-1);
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(s[mid]-s[S-1]>s[T]-s[mid])r=mid-1;
		else if((s[T]-s[mid])-(s[mid]-s[S-1])<rsum)rsum=(s[T]-s[mid])-(s[mid]-s[S-1]),ret=mid,l=mid+1;
		else r=mid-1;
	}
	return ret;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),s[i]=s[i-1]+a[i];
	LL ans=(1LL<<63-1);
	for(int i=2;i<n-1;i++)
	{
		int tx=fd(1,i),ty=fd(i+1,n);
		if(tx==-1)tx=0;
		if(ty==-1)ty=i;
		for(int j=0;j<=1;j++)
			for(int k=0;k<=1;k++)
			{
				int u=min(tx+j,i-1),v=min(ty+k,n-1);
				LL minn=min(min(s[n]-s[v],s[v]-s[i]),min(s[i]-s[u],s[u]-s[0]));
				LL maxx=max(max(s[n]-s[v],s[v]-s[i]),max(s[i]-s[u],s[u]-s[0]));
				ans=min(ans,maxx-minn);
			}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>

struct UFNode
{
	UFNode *parent;
	int rank;
	UFNode() :parent(nullptr), rank(0) {}
};
int MakeSet(UFNode &n)
{
	if (n.rank)
		return 0;
	return n.rank = 1;
}
UFNode &Find(UFNode &n)
{
	if (n.parent == nullptr)
		return n;
	return *(n.parent = &Find(*n.parent));
}
int Union(UFNode &m, UFNode &n)
{
	auto &mr = Find(m), &nr = Find(n);
	if (&mr == &nr)
		return 0;
	if (mr.rank < nr.rank)
		mr.parent = &nr;
	else {
		nr.parent = &mr;
		mr.rank += mr.rank == nr.rank;
	}
	return -1;
}

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	int a[50], b[50];
	for (int i = 0; i < M; i++)
		cin >> a[i] >> b[i];
	int c = 0;
	for (int i = 0; i < M; i++) {
		UFNode f[51];
		int n = 0;
		for (int j = 0; j < N; j++)
			n += MakeSet(f[j]);
		for (int j = 0; j < M; j++)
			if (i != j)
				n += Union(f[a[j]], f[b[j]]);
		c += n > 1;
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256