akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

//constexpr long long MOD = 1000000007;
constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;


number GCD(number a, number b) {
    return b != 0 ? GCD(b, a % b) : a;
}

int main() {
    ll n, k; cin >> n >> k;
    vll a(n);
    ll M=0;
    rep(i, n) {
        cin >> a[i];
        chmax(M,a[i]);
    }
    if (n == 1) {
        cout << (a[0] == k ? "POSSIBLE" : "IMPOSSIBLE") << endl;
        return 0;
    }

    ll g = GCD(a[0], a[1]);
    for (int i = 2; i < n ; i++) g = GCD(g, a[i]);
    cout << ( k % g == 0 && k <= M ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;

}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> red(N);
    int cnt[N];
    for (int i = 0; i < N; i++)
    {
        red[i] = false;
        cnt[i] = 1;
    }
    red[0] = true;

    for (int i = 0; i < M; i++)
    {
        int x, y;
        cin >> x >> y;
        x--; y--;
        if(red[x] == true){
            red[y] = true;
        }
        cnt[x]--;
        cnt[y]++;
        if(cnt[x] == 0){
            red[x] = false;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if(red[i] == true) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <cstdint>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 1000000007;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
constexpr auto PI = 3.14159265358979323846264338327950L;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<string> s(N);
    map<string ,int> mp;
    for (int i = 0; i < N; ++i) {
        cin >> s[i];
        mp[s[i]]++;
    }
    vector<int> a(4,0);
    for (auto x = mp.begin(); x!= mp.end(); ++x) {
        if (x->first == "AC") {
            a[0] = x->second;
        }
        else if (x->first == "WA") {
            a[1] = x->second;
        }
        else if (x->first == "TLE") {
            a[2] = x->second;
        }
        else {
            a[3] = x->second;
        }

    }
    for (int i = 0; i < 4; ++i) {
        if (i==0) {
            cout << "AC x " << a[i] << endl;
        }
        else if (i==1) {
            cout << "WA x " << a[i] << endl;
        }
        else if (i==2) {
            cout << "TLE x " << a[i] << endl;
        }
        else {
            cout << "RE x " << a[i] << endl;
        }
    }
    return 0;

}


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

int main(){
    while(true){
        int n, s, d;
        int xmin=0, xmax=0, ymin=0, ymax=0;
        vector<pair<int, int> > square;
        cin >> n;
        if(!n) break;
        square.push_back(make_pair(0, 0));
        for(int i=0;i<n-1;++i){
            cin >> s >> d;
            if(d==0) square.push_back(make_pair(square[s].first-1,square[s].second));
            else if(d==1) square.push_back(make_pair(square[s].first,square[s].second-1));
            else if(d==2) square.push_back(make_pair(square[s].first+1,square[s].second));
            else if(d==3) square.push_back(make_pair(square[s].first,square[s].second+1));
        }
        for(int i=0;i<n;++i){
            xmin = min(xmin, square[i].first);
            xmax = max(xmax, square[i].first);
            ymin = min(ymin, square[i].second);
            ymax = max(ymax, square[i].second);
        }
        cout << xmax-xmin+1 << ' ' << ymax-ymin+1 << endl;
    }
}

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

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	const int n = s.size();
	reverse(s.begin(), s.end());
	ll answer = 0;
	for(int i = 0, j = 0; i < n; ++i){
		if(s[i] == 'B'){
			answer += i - j;
			++j;
		}
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 720
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000000
#define P1 31
#define P2 37
#define M  1000000007
#define M2 1000000009
#define pii pair<ll,ll>
typedef long long ll;
using namespace std;
const int N = 355001;
const int SQRTN = 320;
const int LOGN = 20;
const long double PI = acos(-1);
const long double TAU = 2*PI;

int freq['z'+1];
string s;
int ans = oo;

int calc(char c,string s){
    string x="";
    int ctr=0;for(int i = 0 ; i < s.size();i++)if(s[i]==c)ctr++;
    if(ctr==s.size())return 0;
    for(int i = 0 ; i < s.size()-1 ; i++){
        if(s[i+1]==c)x+=s[i+1];else x+=s[i];
    }
    return 1+calc(c,x);
}

signed main(){
    cin >> s;
    for(int i = 0 ; i < s.size() ; i++){
        freq[s[i]]++;
    }
    for(int i = 'a' ; i <= 'z' ; i++){
        if(freq[i])ans=min(ans,calc(i,s));
    }
    cout << ans << endl;



}


Measured memory_bytes: 256
import collections
import bisect
n = int(input())
cnt = collections.defaultdict(list)
dat = list(map(int, input().split()))
buf = []
for i in range(n):
    cnt[i - dat[i]].append(i)
#print(buf)
res = 0
for i in range(n):
    x = i + dat[i]
    if x in cnt:
        res += len(cnt[x]) - bisect.bisect_left(cnt[x], x)
print(res)



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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  ll rcnt = 0;
  ll gcnt = 0;
  ll bcnt = 0;
  rep(i, n) {
    if (s[i] == 'R')
      rcnt++;
    else if (s[i] == 'G')
      gcnt++;
    else
      bcnt++;
  }

  ll ans = rcnt * gcnt * bcnt;

  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      ll k = 2 * j - i;
      if (k >= n) continue;
      bool cond = s[i] != s[j] && s[j] != s[k] && s[k] != s[i];
      if (cond) ans--;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3612
#include <cassert>

template <class CommutativeMonoid, template <class> class Container>
class fenwick_tree {

public:
	using value_structure = CommutativeMonoid;
	using value_type = typename value_structure::value_type;
	using container_type = Container<value_type>;
	using const_reference = typename container_type::const_reference;
	using size_type = typename container_type::size_type;

private:
	size_type base_size;
	container_type c;
	static size_type getsize(const size_type size) {
		size_type ret = 1;
		while (ret < size)
			ret <<= 1;
		return ret;
	}

public:
	fenwick_tree() : base_size(0), c() {}
	explicit fenwick_tree(const size_type size)
		: base_size(getsize(size)), c(size + 1, value_structure::identity()) {}

	bool empty() const { return size() == 0; }
	size_type size() const { return c.size() - 1; }

	value_type fold(size_type last) const {
		assert(last <= size());
		value_type ret = value_structure::identity();
		for (; last; last &= last - 1)
			ret = value_structure::operation(c[last], ret);
		return ret;
	}
	template <class F> size_type search(const F &f) const {
		if (f(value_structure::identity()))
			return 0;
		size_type i = 0, k = base_size;
		value_type acc = value_structure::identity();
		while (k >>= 1)
			if ((i | k) < c.size() && !f(value_structure::operation(acc, c[i | k])))
				acc = value_structure::operation(acc, c[i |= k]);
		return i + 1;
	}

	void update(size_type index, const value_type &diff) {
		assert(index < size());
		for (++index; index < c.size(); index += index & ~index + 1)
			c[index] = value_structure::operation(c[index], diff);
	}
};

template <class T> class plus_monoid {
public:
	using value_type = T;
	static value_type operation(const value_type &x, const value_type &y) {
		return x + y;
	}
	static value_type identity() { return value_type(0); }
	static value_type reverse(const value_type &x) { return x; }
};

#include <iostream>
#include <vector>

template<class T> using vec_alias = ::std::vector<T>;

int main() {
	int n, q;
	::std::cin >> n >> q;

	fenwick_tree<plus_monoid<int>, vec_alias> fenwick(n);

	while (q--) {
		int c, x, y;
		::std::cin >> c >> x >> y;

		if (c) {
			::std::cout << fenwick.fold(y) - fenwick.fold(x - 1) << ::std::endl;
		}
		else {
			fenwick.update(x - 1, y);
		}

	}

	return 0;
}



Measured memory_bytes: 3136
import java.io.IOException;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();
            char[] c = s.toCharArray();
 
            System.out.println((char)(c[0]+1));
        }
    }
}


Measured memory_bytes: 22356
inf = float("inf")
n = int(input())
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
    L = list(map(int, input().split()))
    for j in range(L[1]):
        M[L[0]][L[2 * j + 2]] = L[2 * j + 3]


def dijkstra(s):
    color = [0] * n
    d = [inf] * n
    d[s] = 0

    while True:
        mincost = inf
        for i in range(n):
            if color[i] !=1 and d[i] < mincost:
                mincost = d[i]
                u = i
        if mincost == inf: break
        color[u] = 1
        for v in range(n):
            if color[v] != 1 and M[u][v] != inf:
                if d[u] + M[u][v] < d[v]:
                    d[v] = d[u] + M[u][v]

    return d

d = dijkstra(0)
for i,v in enumerate(d):
 print("{} {}".format(i,v))

Measured memory_bytes: 7824
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

int main(void) {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    vector<int> zs, os;
    
    if (all_of(s.begin(), s.end(), [](char c){return c == '1';})) {
        cout << n << endl;
        return 0;
    }
    
    if (s[0]   == '0') os.push_back(0);
    
    int c = 1; // continuous
    repeat (i, n) {
        if (s[i] == s[i+1]) ++c;
        else {
            if (s[i] == '0') {
                zs.push_back(c);
                c = 1;
            }
            else {
                os.push_back(c);
                c = 1;
            }
        }
    }
    
    if (s[n-1] == '0') os.push_back(0);
    assert (zs.size() + 1 == os.size());
    
    //vdump(zs); el;
    //vdump(os); el;
    int ans = 0;
    k = min(k, (int)zs.size());
    repeat_to (i, zs.size() - k) {
        int t = 0;
        repeat_from (a, i, i + k) {
            t += zs[a];
        }
        repeat_from (a, i, i + k + 1) {
            t += os[a];
        }
        //dump(t); el;
        ans = max(ans, t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1020
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-9;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int N = 16;
const int M = 256;

int main(void){
    for(int n, resS, resA, resC; cin >> n, n; cout << resS << " " << resA << " " << resC << endl){
        vi I(n + 1), R(n + 1);
        range(i, 1, n + 1) cin >> I[i];

        double resH = (double)inf;
        rep(s, N){
            rep(a, N){
                rep(c, N){
                    vi O(M);

                    R[0] = s;
                    range(i, 1, n + 1){
                        R[i] = (a * R[i - 1] + c) % M;
                        O[(I[i] + R[i]) % M]++;
                    }

                    double H = 0.;
                    rep(i, M){
                        if(O[i] != 0) H -= (double)O[i] / n * log((double)O[i] / n);
                    }
                    if(H + eps < resH){
                        resH = H;
                        resS = s;
                        resA = a;
                        resC = c;
                    }
                }
            }
        }
    }

	return 0;
}

Measured memory_bytes: 1240
import collections
import itertools as it
import math
import numpy as np

# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()
H, A = map(int, input().split())

c = 0
for i in range(1000000000):
    if H <= 0:
        break
    else:
        c += 1
        H -= A

print(c)

Measured memory_bytes: 21780
#include<stdio.h>
#define MAX 100002
#define NIL -1
void print(int);
void Depth(int,int);

struct Node {int p,l,r;};
struct  Node T[MAX];
int n, D[MAX];

int main(){
  int i,j;
  int id,k,c,t,u;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d",&id,&k);
    for(j = 0; j < k; j++){
      scanf("%d",&c);
      if(j == 0) T[id].l = c;
      else T[t].r = c;
             t = c;
             T[c].p = id;
    }
  }

  for(i = 0; i < n; i++){
    if(T[i].p == NIL) u = i;
  }

  Depth(u,0);

  for(i = 0; i < n; i++) print(i);

  return 0;
}

void Depth(int u,int p){
  D[u] = p;
  if(T[u].r != NIL) Depth(T[u].r,p);
  if(T[u].l != NIL) Depth(T[u].l,p+1);
}

void print(int id){
  int i,c;
  printf("node %d: parent = %d, depth = %d, ",id,T[id].p,D[id]);
  if(T[id].p == NIL) printf("root, ");
  else if(T[id].l == NIL) printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  for(i = 0, c = T[id].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

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

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる
  ll cost; // e.costでその辺の重みにアクセスできる
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}
//素数判定 
//一つ一つの判定ではこっちの方が速い(一つ当たりO(√N))
//一方100までに何個あるかなどはEratosthenesの篩の方が良い（O(NlogN))
bool PN(int x) {
  if (x <= 1) return false; // 1や0,-1は素数ではない
  if (x == 2) return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) return false; // 割れたら素数じゃない
  }
  return true;
}
// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  ll ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}
  
//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N;
  cin >> N;
  cout << modpow(floor(sqrt(N)), 2, LINF) << endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 1e5+100;

int dp[N][4];
int a[N],b[N],c[N];
int n;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    
    for(int i = 1; i<=n; i++) cin>>a[i]>>b[i]>>c[i];
    
    for(int i = 1; i<=n; i++){
        dp[i][1] = max(dp[i-1][2], dp[i-1][3]) + a[i];   //第i天选择a活动
        dp[i][2] = max(dp[i-1][1], dp[i-1][3]) + b[i];   //第i天选择b活动
        dp[i][3] = max(dp[i-1][1], dp[i-1][2]) + c[i];   //第i天选择c活动
    }
    
    cout<<max(max(dp[n][1],dp[n][2]), dp[n][3]);
    return 0;
}

Measured memory_bytes: 5920
n = int(input())

def judge(x):
    y = x
    f3 = 0
    f5 = 0
    f7 = 0
    while y :
        kk = y%10
        if kk == 3:
            f3 = 1
        elif kk == 5:
            f5 = 1
        elif kk == 7:
            f7 = 1
        else:
            return 0
        y = y//10
    return f3 and f5 and f7
def dfs(x,y):
    if x > n:
        return 0
    ans = judge(x)
    ans += dfs(x * 10 + 7, n)
    ans += dfs(x * 10 + 5, n)
    ans += dfs(x * 10 + 3, n)
    return ans
print(dfs(0,n))

Measured memory_bytes: 3064
a, b, c = gets.chomp.split.map(&:to_i)
k = gets.to_i

arr = []
arr.push [a, b, c, 0]

f = false

while !arr.empty?
  t = arr.shift
  x, y, z, cnt = *t
  next if cnt > k
  if x < y && y < z
    f = true
    break
  end
  arr.push([x*2, y, z, cnt+1])
  arr.push([x, y*2, z, cnt+1])
  arr.push([x, y, z*2, cnt+1])
end

if f
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 14304
#include<iostream>
#include<algorithm>
#include<tuple>
#include<queue>

using namespace std;
typedef long long ll;

int H, W;
int filedL[50][50];
int filedR[50][50];
bool used[50][50][50][50];
tuple<int, int> Lstart, Rstart;

int vx1[4] = { 0,1,0,-1 }, vx2[4] = { 0,1,0,-1 };
int vy1[4] = { 1,0,-1,0 }, vy2[4] = { -1,0,1,0 };

int main() {
	while (1) {
		cin >> W >> H;

		if (W == 0 && H == 0)break;

		for (int i = 0; i < H; i++)for (int j = 0; j < W; j++)
			for (int k = 0; k < H; k++)for (int l = 0; l < W; l++)used[i][j][k][l] = false;

		for (int i = 0; i < H; i++)for (int j = 0; j < W; j++)filedL[i][j] = 0, filedR[i][j] = 0;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < 2 * W; j++) {
				char c;
				cin >> c;
				if (j < W) {
					if (c == '.')filedL[i][j] = 0;
					else if (c == '#')filedL[i][j] = 1;
					else if (c == '%')filedL[i][j] = 2;
					else if (c == 'L')get<0>(Lstart) = i, get<1>(Lstart) = j;
					
				}
				else {
					
					if (c == '.')filedR[i][j - W] = 0;
					else if (c == '#')filedR[i][j - W] = 1;
					else if (c == '%')filedR[i][j - W] = 2;
					else if (c == 'R')get<0>(Rstart) = i, get<1>(Rstart) = j - W;
				}
			}
		}
		
		//bfsを行う
		queue <tuple<int, int, int, int>> qu;
		//最初の座標を挿入
		qu.push(make_tuple(get<0>(Lstart), get<1>(Lstart), get<0>(Rstart), get<1>(Rstart)));
		used[get<0>(Lstart)][get<1>(Lstart)][get<0>(Rstart)][get<1>(Rstart)] = true;

		while (qu.size()) {
			auto pos = qu.front(); qu.pop();
			int X1 = get<0>(pos), Y1 = get<1>(pos), X2 = get<2>(pos), Y2 = get<3>(pos);

			//cout << X1 << " " << Y1 << " " << X2 << " " << Y2 << endl;

			//同時にゴールできてるかどうか
			if (filedL[X1][Y1] == 2 && filedR[X2][Y2] == 2) {
				//ゴールに到達
				cout << "Yes" << endl;
				goto nextroop;
			}

			//四方向へと探索を進める
			for (int i = 0; i < 4; i++) {
				int NX1 = X1 + vx1[i], NY1 = Y1 + vy1[i], NX2 = X2 + vx2[i], NY2 = Y2 + vy2[i];

				//範囲外オーバーあるかどうかを判断
				if (NX1 < 0)NX1 = 0;
				if (NX1 >= H)NX1 = H - 1;
				if (NY1 < 0)NY1 = 0;
				if (NY1 >= W)NY1 = W - 1;
				if (NX2 < 0)NX2 = 0;
				if (NX2 >= H)NX2 = H - 1;
				if (NY2 < 0)NY2 = 0;
				if (NY2 >= W)NY2 = W - 1;
				//壁に当たってるかどうかを判断　これは上のと被らないはず
				//行先が壁ならば動かない
				if (filedL[NX1][NY1] == 1) {
					NX1 = X1, NY1 = Y1;
				}
				if (filedR[NX2][NY2] == 1) {
					NX2 = X2, NY2 = Y2;
				}
				//二人の行先がどちらもすでに探索済みの場所ならば行かない。これはそもそも動いてないパターンも弾くことができる
				if (used[NX1][NY1][NX2][NY2])continue;
				//片方でも先にゴールならばアウト
				if ((filedL[NX1][NY1] == 2 && filedR[NX2][NY2] != 2) ||
					filedL[NX1][NY1] != 2 && filedR[NX2][NY2] == 2) {
					continue;
				}
				//その行き先をまたキューに入れる。

				used[NX1][NY1][NX2][NY2] = true;
				qu.push(make_tuple(NX1, NY1, NX2, NY2));

			}
		}

		cout << "No" << endl;

	nextroop:;
	}
	return 0;
}


Measured memory_bytes: 9980
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

int parse(int ne, vector<int>& v) {
	int buf = (1 << ne) | 1;
	int p = ne;
	for (auto itr : v) {
		bitset(buf, p + itr);
		p += itr;
	}
	return buf;
}

ll dp[41][131072] = {};
int n, x, y, z;
ll func(int ps, int st) {
	st %= 131072;
	if (dp[ps][st])
		return dp[ps][st];
	if (ps >= n)
		return 1;
	int buf = st;
	ll ret = 0;
	rep(i, 1, 11) {
		int cur = buf << i;
		cur |= 1;
		if (!(bitcheck(cur, z) && bitcheck(cur, y + z) && bitcheck(cur, x + y + z))) {
			ret += func(ps + 1, cur);
			ret %= MODU;
		}
		else
			printf("");
	}
	return dp[ps][st] = ret;
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x*x%mod;
		n >>= 1;
	}
	return res;
}
signed main() {

	scanf("%d %d %d %d", &n, &x, &y, &z);

	printf("%d\n", (mod_pow(10,n, MODU) - func(0, 1) + MODU) % MODU);

	return 0;
}

Measured memory_bytes: 39168
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

signed main() {
	int N, A, B;
	int X[100005];
	cin >> N >> A >> B;
	REP(i, N) {
		cin >> X[i];
	}

	ll ans = 0;
	REP(i, N - 1) {
		ans += min((X[i + 1] - X[i]) * A, B);
	}

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

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

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

  ll N; cin >> N;
  ll MAX;
  for (ll i = 0; i <= N; i++) {
    if (i * (i + 1) / 2 == N) MAX = i;
    else if (i * (i + 1) / 2 < N) MAX = i + 1;
    else break;
  }
  for (ll i = MAX; i >= 1; i--) {
    if (N >= i) {
      cout << i << '\n';
      N -= i;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i< (n);++i)

using namespace std;

int main(){
    int K;
    cin>>K;
    int count=0;
    
    if(K%2==1){
       count= ((K+1)/2)*(K/2);
    }else{
        count=(K/2)*(K/2);
    }
    
        
    cout<<count<<endl;
    

}


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


Measured memory_bytes: 256
N,H=map(int,input().split())
a=[0]*N
b=[0]*N
for i in range(N):
    a[i],b[i]=map(int,input().split())
b.sort(reverse=True)
a.sort(reverse=True)
cnt=0
for i in range(N):
    if b[i]>=a[0]:
        H=H-b[i]
        cnt+=1
    if H<=0:
        break

if H>0:
    if H%a[0]==0:
        cnt+=H//a[0]
    else:
        cnt+=H//a[0]+1
print(cnt)

Measured memory_bytes: 11312
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
long long ni(long long ta, vector<long long> & v) {

}
long long rui(long long n, long long k, long long p) {
	if (k == 0) {
		return 1;
	}
	else {
		long long a = rui(n, k / 2, p);
		if (k % 2 == 0) {
			return (a*a) % p;
		}
		return (((a*a) % p)*n) % p;
	}
}
int main(){
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	cout <<( n - (a + b)) + c << endl;
	return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
int ctoi(char c);
int main(){
  int N;
  char str[3][101];
  int i,j;
  int change = 0;
  scanf("%d%s%s%s",&N,str[0],str[1],str[2]);
  
  for(i=0;i<N;i++){
    if((str[0][i]-str[1][i])*(str[1][i]-str[2][i])*(str[2][i]-str[0][i]) != 0){
      change+=2;
    }
    else if(str[0][i] == str[1][i] && str[0][i] == str[2][i]){
      
    }
    else{
     change++;
    }
  }
  printf("%d",change);
}


Measured memory_bytes: 128
from collections import deque
import math; floor,ceil = math.floor,math.ceil
import sys; input = lambda: sys.stdin.readline().rstrip()
aint = lambda: int(input()); ints = lambda: list(map(int, input().split()))
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
is_even = lambda x: True if x%2==0 else False

def main():
  r = aint()
  print(2*3.1416*r)

if __name__ == '__main__':
  main()

Measured memory_bytes: 9428
#include <bits/stdc++.h>
#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<n;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 10000000007
#define modpro 99824435
using namespace std;

void solve(){
	double n;
	cin>>n;
	//cout<<ceil(double(n)/2)<<endl;
	printf("%.6f",ceil(double(n)/2)/n);
}
int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}



Measured memory_bytes: 3784
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	for i := len(s); i >= len(t); i-- {
		ss := s[i-len(t) : i]
		ok := true
		for j := 0; j < len(t); j++ {
			if ss[j] != t[j] && ss[j] != '?' {
				ok = false
			}
		}
		if ok {
			ans := s[0:i-len(t)] + t + s[i:]
			fmt.Println(strings.Replace(ans, "?", "a", -1))
			return
		}
	}
	fmt.Println("UNRESTORABLE")
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA

int main(){
    ll t1,t2; cin >> t1 >> t2;
    ll a1,a2,b1,b2;
    cin >> a1 >> a2 >> b1 >> b2;
    ll one=(a1-b1)*t1;
    ll two=(a2-b2)*t2;
    ll a=two+one;
    if(a==0){
        cout << "infinity" << endl;
        return 0;
    }
    if(one>0&&a>0){
        cout << 0 << endl;
        return 0;
    }
    if(one<0&&a<0){
        cout << 0 << endl;
        return 0;
    }
    if(one<0) one*=-1;
    if(a<0) a*=-1;
    if(one%a!=0) cout << 2*(one/a)+1;
    else cout << 2*(one/a);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000

int main() {

	LL n, i, arr[10000], k, sum = 0;
	
	cin>>n>>k;
	for(i = 0 ; i < n ; i++) cin>>arr[i];

	sort(arr, arr+n);

	for(i = 0 ; i < k ; i++) {
		sum += arr[i];
	}

	cout<<sum<<endl;

	return 0;

}

Measured memory_bytes: 3644
hantei = ["dream", "dreamer", "erase", "eraser"]
s = input()
len_s = len(s)
s = s+"0000000000000"

checker = 1
i = 0
while i < len_s:
    if s[i:i+5] == "dream":
        if s[i+5:i+7] == "er":
            if s[i+7] =="a":
                i += 5
            else:
                i += 7
        else:
            i += 5
    elif s[i:i+5] == "erase":
        if s[i+5] == "r":
            i += 6
        else:
            i += 5
    else:
        checker = 0
        break
if checker:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
package main

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

func main() {
	var S string
	var r int
	s := bufio.NewScanner(os.Stdin)
	b := make([]byte, 1000000)
	s.Buffer(b, 1000000)
	s.Scan()
	S = s.Text()
	for i := 0; i < len(S)-1; i++ {
		if S[i:i+1] != S[i+1:i+2] {
			S = S[:i] + S[i+2:]
			i = i - 2
			r += 2
		}
		if i < -1 {
			i = -1
		}
	}
	fmt.Println(r)
}

Measured memory_bytes: 13056
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<climits>
#define int long long
using namespace std;
inline int read(){
	int f=1,ans=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return f*ans;
}
const int MAXN=200001;
int st[MAXN][21],n,a[MAXN];
int Query(int l,int r){
	int k=log2(r-l+1);
	return min(st[l][k],st[r-(1<<k)+1][k]);
}
int Ql(int x){
	int l=1,r=x-1,minn=INT_MAX;
	while(l<=r){
		int mid=l+r>>1;
		if(Query(mid,x-1)>a[x]) r=mid-1,minn=min(minn,mid);
		else l=mid+1;
	}return minn;
}
int Qr(int x){
	int l=x+1,r=n,maxn=	INT_MIN;
	while(l<=r){
		int mid=l+r>>1;
		if(Query(x+1,mid)>=a[x]) l=mid+1,maxn=max(maxn,mid);
		else r=mid-1; 
	}return maxn;
}int ans;
signed main(){
//	freopen("6.in","r",stdin);
	n=read();
	for(int i=1;i<=n;i++) a[i]=st[i][0]=read();
	for(int j=1;j<=log2(n);j++)
		for(int i=1;i+(1<<j)-1<=n;i++) st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
	for(int i=1;i<=n;i++){
		int l=Ql(i),r=Qr(i);
		if(l==INT_MAX) l=i;
		if(r==INT_MIN) r=i;
		int lena=i-l,lenb=r-i;
		ans+=(lena+lenb+1+lena*lenb)*a[i];
	}printf("%lld\n",ans);
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

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

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 20;
char s[N][N];
int n,h,w,result;
ll a[N];
int d[N*N][N*N];

void warshall_floyd() {
  rep(k,h*w) rep(i,h*w) rep(j,h*w) {
    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
}

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> h >> w;
  rep(i,N*N) rep(j,N*N) {
    if(i != j) d[i][j] = INF;
  }
  rep(i,h) {
    rep(j,w) {
      cin >> s[i][j];
    }
  }
  rep(i,h) rep(j,w) {
    if(i != 0 && s[i][j] == '.' && s[i-1][j] == '.') {
      d[i*w+j][(i-1)*w+j] = 1; d[(i-1)*w+j][i*w+j] = 1;
    }
    if(j != 0 && s[i][j] == '.' && s[i][j-1] == '.') {
      d[i*w+j][i*w+j-1] = 1; d[i*w+j-1][i*w+j] = 1;
    }
  }
  warshall_floyd();
  rep(i,h*w) rep(j,h*w) {
    // cout << "d[" << i << "][" << j << "] = " << d[i][j] << endl;
    if (d[i][j] != INF) result = max(d[i][j], result);
  }
  cout << result << endl;
}


Measured memory_bytes: 896
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

const MOD: usize = 1000000007;

fn add(a: usize, b: usize) -> usize {
    (a + b) % MOD
}

fn solve(s: &[char]) -> usize {
    let mut dp = vec![vec![0; 4]; s.len()+1];
    dp[s.len()][3] = 1;
    for i in (0..s.len()).rev() {
        for j in 0..4 {
            if s[i] == '?' {
                dp[i][j] = add(dp[i][j], 3 * dp[i+1][j]);
            } else {
                dp[i][j] = add(dp[i][j], dp[i+1][j]);
            }
        }
        if s[i] == '?' || s[i] == 'A' { dp[i][0] = add(dp[i][0], dp[i+1][1]) };
        if s[i] == '?' || s[i] == 'B' { dp[i][1] = add(dp[i][1], dp[i+1][2]) };
        if s[i] == '?' || s[i] == 'C' { dp[i][2] = add(dp[i][2], dp[i+1][3]) };
    }
    return dp[0][0];
}

fn main() {
    input!{
      ss: chars,
    }
    let ans = solve(&ss);
    println!("{}", ans);
}


Measured memory_bytes: 10492
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

//左子右兄弟表現の実装
struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if ( T[u].p == NIL ) cout << "root, ";
    else if ( T[u].l == NIL ) cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    
    for ( i = 0, c = T[u].l; c != NIL; i++, c = T[c].r ) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int rec(int u, int p) {
    D[u] = p;
    if ( T[u].r != NIL ) rec(T[u].r, p);  //節の右兄弟が存在する場合、同じ深さ情報を設定
    if ( T[u].l != NIL ) rec(T[u].l, p + 1);
}

int main() {
    int i, j, d, v, c, l, r;
    cin >> n;   //節点の個数
    for ( i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;
    
    //親、左の子、右の兄弟の情報を格納、ない場合はNIL
    for ( i = 0; i < n; i++ ) {
        cin >> v >> d;   //v:節点の番号　d:次数
        for ( j = 0; j < d; j++ ) {
            cin >> c;   //節点の子
            if ( j == 0 ) T[v].l = c;   //左の子
            else T[l].r = c;   //右の兄弟
            l = c;
            T[c].p = v;   //親
        }
    }
    //親無し(根)のとき
    for ( i = 0; i < n; i++ ) {
        if (T[i].p == NIL) r = i;   //入力例の場合、r=0
    }
    
    rec(r, 0);
    
    for ( i = 0; i < n; i++ ) print(i);
    
    return 0;
}


Measured memory_bytes: 7764
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

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

	int r, g, b;
	cin >> r >> g >> b;
	cout << ((r*100+g*10+b)%4==0 ?"YES":"NO") << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())

dp = [10**7 for i in range(n+1)]
dp[0] = 0
for i in range(n+1):
    for j in range(7):
        if i >= 6**j:
            dp[i] = min(dp[i], dp[i-6**j]+1)
    for k in range(6):
        if i >= 9**k:
            dp[i] = min(dp[i], dp[i-9**k]+1)
print(dp[n])

Measured memory_bytes: 44784
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
using namespace std;
using ll = long long;
int main(){
  ll n, x;
  cin >> n >> x;
  vector<ll> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  ll ans = 0;
  for(int i = 0; i < n - 1; i++){
    if(x < (a[i] + a[i+1])){
      ll df = a[i] + a[i+1] - x;
      if(a[i+1] - df >= 0){
        ans += (a[i] + a[i+1])-x;
        a[i+1] -= (a[i] + a[i+1])-x;
      }
      else{
        ans += df;
        df -= a[i+1];
        a[i+1] = 0;
        a[i] -= df;
      }
    }
  }
//  for(int i = 0; i < n; i++){
//    cout << a[i] << " " ;
//  }
//  cout << endl;
  cout << ans << endl;
  return 0;
} 


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    s64 a[n + 2];
    rep (i, n + 1) cin >> a[i];
    a[n + 1] = 0;

    s64 l[n + 2];
    s64 r[n + 1];
    rep (i, n + 1) l[i] = CEIL(a[i + 1], 2);
    rep (i, n) r[i + 1] = min(a[i + 2], 2 * r[i] - a[i + 1]);
    r[n] = l[n];
    for (int i = n - 1; i >= 0; --i)
    {
        r[i] = r[i + 1] + a[i + 1];
    }
    l[n + 1] = 0;
    r[0] = 1 - a[0];
    rep (i, n)
    {
        r[i + 1] = min(r[i + 1], 2 * r[i] - a[i + 1]);
    }

    rep (i, n + 1)
    {
        if (l[i] > r[i])
        {
            cout << "-1\n";
            return 0;
        }
    }

    s64 ans = 0;
    rep (i, n + 1)
    {
        ans += r[i] + a[i];
    }

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



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

int main(){
  int n,k,q;
  cin>> n >> k >> q;
  vector<int> v(n,k-q);
  
  int num;
  for (int i=0; i<q; i++){
    cin>> num;
    v.at(num-1)++;
  }
  string ans;
  for (int i=0; i<n; i++){
    if (v.at(i)>0) ans="Yes";
    else ans="No";
    cout<< ans <<endl;
  }
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[]po=new int[n];
        for(int i=0;i<n;i++)po[i]=sc.nextInt();
        int ans=0;
        for(int i=2;i<n;i++){
            if((po[i-2]<po[i-1]&&po[i-1]<po[i])||(po[i-2]>po[i-1]&&po[i-1]>po[i]))
            ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21716
from collections import Counter
n = int(input())
s = list(input())
num_w = 0
num_e = Counter(s[1:])['E']
ans = num_e
for i in range(1, n):
    if s[i-1] == 'W':
        num_w += 1
    if s[i] == 'E':
        num_e -= 1
    ans = min(ans, num_w + num_e)
print(ans)

Measured memory_bytes: 8388
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

bool isok(ll x){
    bool a,b,c;
    a=false;
    b=false;
    c=false;
    while(x!=0){
        if(x%10==3) a=true;
        if(x%10==5) b=true;
        if(x%10==7) c=true;
        x /=10;
    }
    if(a&&b&&c){
        return true;
    }else{
        return false;
    }
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin >> n;
  int cnt = 0;
  while(n>(ll)pow(10,cnt)){
      cnt++;
  }
  vector<ll> q[cnt+2];
  q[0].push_back(3);
  q[0].push_back(5);
  q[0].push_back(7);
  REP(i,cnt-1){
      REP(j,q[i].size()){
          ll tmp = q[i][j];
          q[i+1].pb(tmp + (ll)3*(ll)pow(10,i+1));
          q[i+1].pb(tmp + (ll)5*(ll)pow(10,i+1));
          q[i+1].pb(tmp + (ll)7*(ll)pow(10,i+1));
      }
  }
  ll ans = 0;
  REP(i,cnt){
      REP(j, q[i].size()){
          if(q[i][j] <= n && isok(q[i][j])) ans++;
      }
  }
  cout << ans << endl;

}

Measured memory_bytes: 768