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

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

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

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

template <typename T>
class LazySegmentTree {
private:
    std::vector<T> vec, lazy;
    int sz;

public:
    explicit LazySegmentTree(int n) noexcept {
        sz = 1;
        while (sz < n) sz <<= 1;
        vec.assign(sz * 2 - 1, 0);
        lazy.assign(sz * 2 - 1, 0);
    }
    void set_value(int idx, T val) noexcept {
        vec[sz - 1 + idx] = val;
    }
    void build() noexcept {
        for (int i = sz - 2; i >= 0; i--) {
            vec[i] = vec[i * 2 + 1] + vec[i * 2 + 2];
        }
    }
    void eval(int k, int l, int r) noexcept {
        if (lazy[k] == 0) return;
        vec[k] += lazy[k];
        if (r - l > 1) {
            lazy[k * 2 + 1] += lazy[k] / 2;
            lazy[k * 2 + 2] += lazy[k] / 2;
        }
        lazy[k] = 0;
    }
    void _update(int a, int b, T x, int k, int l, int r) noexcept {
        eval(k, l, r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] += x * (r - l);
            eval(k, l, r);
        }
        else {
            _update(a, b, x, k * 2 + 1, l, (l + r) >> 1);
            _update(a, b, x, k * 2 + 2, (l + r) >> 1, r);
            vec[k] = vec[k * 2 + 1] + vec[k * 2 + 2];
        }
    }
    void update(int a, int b, T x) noexcept {
        _update(a, b, x, 0, 0, sz);
    }
    T _query(int a, int b, int k, int l, int r) noexcept {
        if (b <= l || r <= a) return 0;
        eval(k, l, r);
        if (a <= l && r <= b)
            return vec[k];
        else {
            T res = _query(a, b, k * 2 + 1, l, (l + r) >> 1);
            res += _query(a, b, k * 2 + 2, (l + r) >> 1, r);
            return res;
        }
    }
    T query(int a, int b) noexcept {
        return _query(a, b, 0, 0, sz);
    }
};

void solve() {
    ll N, Q;
    cin >> N >> Q;
    LazySegmentTree<ll> seg(N);
    while (Q--) {
        int mode;
        cin >> mode;
        if (mode == 0) {
            ll x, y, z;
            cin >> x >> y >> z;
            --x, --y;
            seg.update(x, y + 1, z);
        }
        else if (mode == 1) {
            ll x, y;
            cin >> x >> y;
            --x, --y;
            cout << seg.query(x, y + 1) << "\n";
        }
    }
}

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

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


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

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    int n, m, q;
    scanf("%d %d %d", &n, &m, &q);
    int t[n+1][n+1];
    rep(i, 0, n+1){
        rep(j, 0, n+1){
            t[i][j] = 0;
        }
    }
    rep(i, 0, m){
        int l, r;
        scanf("%d %d", &l, &r);
        t[l][r]++;
    }
    rep(i, 1, n+1){
        rep(j, 1, n+1){
            t[i][j] = t[i-1][j] + t[i][j-1] + t[i][j] - t[i-1][j-1];
        }
    }
    int ans[q];
    rep(i, 0, q){
        int l, r;
        scanf("%d %d", &l, &r);
        ans[i] = t[r][r] - t[r][l-1] - t[l-1][r] + t[l-1][l-1];
    }
    rep(i, 0, q){
        printf("%d\n", ans[i]);
    }

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
 
int main(){
    string S;
    cin >> S;
    ll res = 0;
    REP(i, 4) {
        if (S[i]=='+') res++;
        else res--;
    }
    cout << res << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long int n, a, b, setNum, remainBall;

	scanf("%ld%ld%ld",&n, &a, &b);
	
	/* 青と赤のボールを1セットとし、n番目までに完全な形で並ぶセット数を数える */
	setNum = n / (a + b);
	remainBall = n % (a + b);

	/* 残りのボール数が1セット当たりの青ボール数以下なら、残りのボールはすべて青 */
	if (remainBall <= a)
	{
		printf("%ld", a * setNum + remainBall);
	}
	else
	{
		printf("%ld", a * setNum + a);
	}

	return 0;
}

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

void PrintVector(vector<int> A, int N)
{
    for (int i = 0; i < N; i++)
    {
        if (i != N - 1)
        {
            cout << A[i] << ' ';
        }
        else
        {
            cout << A[i] << endl;
        }
    }
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    int cnt = 0;
    for (int i = 1; i < N; i++)
    {
        for (int j = 0; j < N - i; j++)
        {
            if (A[j] > A[j + 1])
            {
                swap(A[j], A[j + 1]);
                cnt++;
            }
        }
    }
    PrintVector(A, N);
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3164
import sys
def main():
    for line in sys.stdin:
        n, x = map(int, line.split())
        if n == 0 and x == 0:
            break
        else:
            cnt = 0
            for i in range(1, n - 1):
                for j in range(i + 1, n):
                    for k in range(j + 1, n + 1):
                        if i + j + k == x:
                            cnt += 1
            print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 7776
// g++ -O3 -fmax-errors=1 -fsanitize=undefined -fsanitize=address -sanitize=leak 
#include <bits/stdc++.h>

using namespace std;

using Int = int64_t;

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

  Int b_total = 0;
  Int small_sum = 0, large_sum = 0;
  priority_queue<Int, vector<Int>, less<Int>> small;
  priority_queue<Int, vector<Int>, greater<Int>> large;

  auto push = [&](Int a) {
    if (small.empty() || a <= small.top()) {
      small.push(a);
      small_sum += a;
    } else {
      large.push(a);
      large_sum += a;
    }
    while (large.size() > small.size()) {
      Int x = large.top();
      small_sum += x;
      large_sum -= x;
      small.push(x);
      large.pop();
    }
    while (small.size() >= large.size() + 2) {
      Int x = small.top();
      small_sum -= x;
      large_sum += x;
      small.pop();
      large.push(x);
    }
  };
  for (int i = 0; i < n; ++i) {
    int c; cin >> c;
    if (c == 1) {
      Int a, b;
      cin >> a >> b;
      push(a);
      b_total += b;
    } else {
      Int x = small.top();
      Int y = small.size()*x - small_sum
            - large.size()*x + large_sum + b_total;
      cout << x << " " << y << endl;
    }
  }
}


Measured memory_bytes: 3828
N,A,B = map(int, input().split())
result = 0

def FindSomeOfDegit(x):
    count = 0
    while x > 0:
        count += x%10 
        x = x // 10
    return count

for i in range(N+1):
    count = FindSomeOfDegit(i)
    if A <= count <= B:
        result += i

print(result)

Measured memory_bytes: 9128
#include "bits/stdc++.h"
using namespace std;
int n, m;
long long a[5005];
int sp[13][5005][205];
int logx[5005];
const int logn = 12;

int getMin(int l, int r, int j) {
	int sz = logx[r - l + 1];
	return max(sp[sz][l][j], sp[sz][r - (1 << sz) + 1][j]);
}

long long getVal(int l, int r) {
	long long ans = a[l] - a[r];
	for(int j = 1; j <= m; j++) {
		ans += getMin(l, r, j);
	}
	return ans;
}


int search(int b, int e, int x, int y) {
	if(b == e) {
		// cout << getVal(x, b) << ' ' << getVal(y, b) << endl;
		return getVal(x, b) >= getVal(y, b) ? b : n + 1;
	}
	int mid = (b + e) >> 1;
	if(getVal(x, mid) >= getVal(y, mid)) {
		return search(b, mid, x, y);
	} else {
		return search(mid + 1, e, x, y);
	}
}
int better(int x, int y) {
	return search(max(x, y), n, x, y);
}

int main(int argc, char const *argv[])
{

	scanf("%d %d", &n, &m);
	for(int i = 2; i <= n; i++) {
		scanf("%lld", &a[i]);
		a[i] += a[i - 1];
	}
	logx[1] = 0;
	for(int i = 2; i <= n; i++) {
		logx[i] = logx[i >> 1] + 1;
	} 
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			scanf("%d", &sp[0][i][j]);
		}
	}
	for(int j = 1; j <= m; j++) {
		for(int k = 1; k <= logn; k++) {
			for(int i = 1; i <= n; i++) {
				if(i + (1 << (k - 1)) <= n) {
					sp[k][i][j] = max(sp[k - 1][i][j], sp[k - 1][i + (1 << (k - 1))][j]);
				}
			}
		}
	}
	long long ans = getVal(1, 1);
	vector <int> v;
	vector <int> opt;
	v.push_back(1);
	opt.push_back(1);

	for(int i = 2; i <= n; i++) {
		while(!v.empty()) {
			int change = better(i, opt.back());
			if(change <= v.back()) {
				opt.pop_back();
				v.pop_back();
			} else {
				if(change <= n) {
					opt.push_back(i);
					v.push_back(change);
				}
				break;
			}
		}
		int idx = upper_bound(v.begin(), v.end(), i) - v.begin() - 1;
		ans = max(ans, getVal(opt[idx], i));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 51456
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int N,M; cin >>N >>M;
  vector<int> cost(M), boxes(M);
  // 各々、i番目の鍵に関して
  // 値段、開けられる宝箱の集合
  rep(i, M){
    cin >>cost[i];
    int b; cin >>b;
    ll box = 0;
    rep(j, b){
      int c; cin >>c; c--;
      box += 1 << c;
    }
    boxes[i] = box;
  }
  vector<vector<int>> dp(M+1, vector<int>(1<<N, 1000000000));
  dp[0][0] = 0;
  // dp[i][S] := i番目までの鍵を用いて宝箱の集合Sを全て開けるために必要な費用の最小値
  for (int i=0; i<M; i++){
    for (int S=0; S<(1<<N); S++){
      // i番目の鍵を購入するかしないか
      chmin(dp[i+1][S | boxes[i]], dp[i][S] + cost[i]);
      chmin(dp[i+1][S], dp[i][S]);
    }
  }
  int res = dp[M][(1<<N)-1];
  cout <<(res == 1000000000 ? -1 : res) <<endl;
}


Measured memory_bytes: 16384
import heapq 
n = int(input())
An = list(map(int, input().split()))
former = An[:n]
latter = An[2*n:]
latter = list(map(lambda x:-x, latter))
heapq.heapify(former)
heapq.heapify(latter)

sum_former = sum(former)
sum_latter = sum(latter)

former_list = [0]*(n+1) 
latter_list = [0]*(n+1) 
former_list[0] = sum_former 
latter_list[0] = sum_latter 

for i in range(n, 2*n):
  heapq.heappush(former, An[i])
  m = heapq.heappop(former)
  former_list[i-n+1] = former_list[i-n] + An[i] - m 

for i in range(2*n-1, n-1, -1):
  heapq.heappush(latter, -An[i])
  m = heapq.heappop(latter)
  latter_list[2*n-i] = latter_list[2*n-i-1] - An[i] - m

latter_list.reverse()
ans = -float('inf')
for i in range(n+1):
  ans = max(ans, former_list[i]+latter_list[i])
print(ans)

Measured memory_bytes: 121360
def main():
    s=input()
    if s=='SUN':
        print(7)
    elif s=='MON':
        print(6)
    elif s=='TUE':
        print(5)
    elif s=='WED':
        print(4)
    elif s=='THU':
        print(3)
    elif s=='FRI':
        print(2)
    elif s=='SAT':
        print(1)

if __name__=='__main__':
    main()


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

int main(){
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    for(int i = 0; i < H;i++){
        if(i < B){
            for(int j = 0; j < W;j++){
                //cout << i <<" "<< A << endl;
                if(j < A )cout << 0;
                else cout << 1;
            }
        }else{
            for(int j = 0; j < W;j++){
                //cout << i <<" "<< A << endl;
                if(j < A)cout << 1;
                else cout << 0;
            }
        }
        cout << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

struct job{
    int day,point;
};
int n,m;
vi a,b;
vector<vi> ab;

int main() {
    //n=仕事の数
    //m=日数
    cin>>n>>m;
    a.resize(n);
    b.resize(n);
    ab.resize(m);
    REP(i,n){
        cin>>a[i]>>b[i];
        if(a[i]<=m) ab[a[i]-1].emplace_back(b[i]);
    }

    priority_queue<int> pque;
    ll ans = 0;
    REP(i,m){
        REP(j,ab[i].size())
            pque.push(ab[i][j]);
        
        if(!pque.empty()){
            ans += pque.top();
            pque.pop();
        }
    }
   
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6400
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

constexpr int INF{1001001001};
constexpr lint LINF{1001001001001001001ll};
constexpr int MOD{(int)1e9 + 7};
constexpr double EPS{1e-9};
const double PI{acos(-1)};
constexpr int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == (lint)(v.size() - 1) ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  int N = in();
  vi a(100001, 0);
  rep(i, N) {
    int v = in();
    a[v]++;
    if (v - 1 >= 0) a[v - 1]++;
    if (v + 1 <= 100000) a[v + 1]++;
  }

  print(*max_element(all(a)));
}


Measured memory_bytes: 640
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
na = lambda : map(int, stdin.readline().split())
ni = lambda : int(ns())
def main():
  n = ni()

  def indict(a, k):
    if k in a:
      a[k] += 1
    else:
      a[k] = 1

  def indict0(a, k, v):
    if k in a:
      a[k] = min(v, a[k])
    else:
      a[k] = v

  res = {}
  allin = {}
  d = {}
  for _ in range(n):
    s = ns()
    for e in s:
      indict(d, e)
    for k, v in d.items():
      indict(allin, k)
      indict0(res, k, v)
    res
    d = {}

  ans = ""
  for k, v in allin.items():
    if v != n:
      continue
    ans += res[k] * k
  print("".join(sorted(ans)))
main()

Measured memory_bytes: 3064
n, m = map(int, input().split())
a = [0] * (n+2)
a[0] = 1
for _ in range(m): a[int(input())] = -1
for i in range(n):
  if a[i] != -1:
    if a[i+1] != -1:
      a[i+1] += a[i]
    if a[i+2] != -1:
      a[i+2] += a[i]
print(a[n] % 1000000007)

Measured memory_bytes: 462708
/*
 * ITP1_4C.c
 *
 *  Created on: 2016/05/28
 *      Author: TakaakiShogaki
 */

#include<stdio.h>

int main(){
	int a,b;
	char op;

	while(1){
	scanf("%d %c %d",&a,&op,&b);
	if(op=='+')
		printf("%d\n",a+b);
	else if(op=='-')
		printf("%d\n",a-b);
	else if(op=='/')
		printf("%d\n",a/b);
	else if(op=='*')
		printf("%d\n",a*b);
	else if(op=='?')
		break;
	}

return 0;
}

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

using namespace std;

int cumsum_m[1000000];
vector<int> c_idx, d_idx;

long count_k(int l, int r){
    return cumsum_m[r]-cumsum_m[l];
}

int main(){
    int N;
    string S;
    int Q;
    cin >> N;
    cin >> S;
    cin >> Q;
    int cnt = 0;
    c_idx.push_back(-1);
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'M') cnt++;
        if(S[i] == 'D') d_idx.push_back(i);
        if(S[i] == 'C') c_idx.push_back(i);
        cumsum_m[i] = cnt;
    }
    for(int i = 0; i < Q; i++){
        int k;
        cin >> k;
        int cl = 0, cr  = 0;
        long tmp = 0;
        long ans = 0;
        while(cl+1 < c_idx.size() && c_idx[cl] < d_idx[0]){
            cl++;
        }
        while(cr+1 < c_idx.size() && c_idx[cr+1] < d_idx[0]+k){
            cr++;
        }
        if(c_idx[cl] > d_idx[0] && c_idx[cr] < d_idx[0]+k){
            for(int j = cl; j <= cr; j++){
                tmp += count_k(d_idx[0], c_idx[j]);
            }
        }
        ans += tmp;
        //cout << ans << ' ' << cl << ' ' << cr << endl;
        for(int j = 1; j < d_idx.size(); j++){
            int diff = cr-cl+1;
            int cnt_dec = 0;
            int prev_cl = cl;
            while(cl+1 < c_idx.size() && c_idx[cl] < d_idx[j]){
                if(c_idx[cl] > d_idx[j-1]) tmp -= count_k(d_idx[j-1], c_idx[cl]);
                cl++;
                cnt_dec++;
            }
            //cout << tmp << endl;
            if(c_idx[prev_cl] > d_idx[j-1]) tmp -= max(diff-cnt_dec, 0)*count_k(d_idx[j-1] , d_idx[j]);
            //cout << tmp << endl;
            while(cr+1 < c_idx.size() && c_idx[cr+1] < d_idx[j]+k){
                cr++;
                if(c_idx[cr] > d_idx[j]) tmp += count_k(d_idx[j], c_idx[cr]);
            }
            if(c_idx[cl] > d_idx[j] && c_idx[cr] < d_idx[j]+k) ans += tmp;
            else tmp = 0;
            //cout << ans << ' ' << tmp << ' ' << cl << ' ' << cr << endl;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 9596
n, d = (int(x) for x in input().split())
X = [[int(x) for x in input().split()] for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(n - i - 1):
        dis_sq = 0
        for k in range(d):
            dis_sq += (X[i][k] - X[i+j+1][k]) ** 2
        dis = dis_sq ** 0.5
        if dis.is_integer():
            ans += 1
print(ans)

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

int main(){
    int n,d;
    cin >> n >> d;
    vector<double>x(n);
    vector<double>y(n);
    for(int i = 0; i < n; i++)cin >> x.at(i) >> y.at(i);

    int count = 0;
    for(int i = 0; i < n; i++){
        if(sqrt(x[i]*x[i]+y[i]*y[i]) <= d)count++;
    }
    cout << count;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
} 
ll lcm(ll a, ll b){
    return a/gcd(a,b)*b;//オーバーフロー対策
}
int main(){ 
  int n;
  cin >> n;
  vector<ll> t(n);
  rep(i,n) cin >> t[i];
  ll d = 0;
  ll res = 1LL;
  for (int i = 0; i < n; i++) {
    res = lcm(res, t[i]);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

//ここから

void solve(){
  ll x;
  cin>>x;
  for(ll i=1;i<=x;++i){
    if((i*(i+1))/2>=x){
      cout<<i<<endl;
      return;
    }
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


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

typedef long long ll;
#define re(n) cin >> n
#define all(a) a.begin(),a.end()
#define ff(i,x,n) for(ll i=(int)x;i<(int)n;i++)
#define f(i,n) ff(i,0,n)
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define te(t) ll t; re(t); while(t--)

int main(){
	ll n;
	re(n);
	ll k;
	re(k);
	ll a[n];
	f(i,n){
		re(a[i]);
	}
	ll dp[n]={0};
	if(n>=2){
		dp[1] = abs(a[0]-a[1]);
	}
	ff(i,2,n){
		ll j=1;
		ll mins = LLONG_MAX;
		while(j<=k){
			if(i-j<0) break;
//			cout << abs(a[i]-a[i-j])+dp[i-j];
//			cout << i << " " << j << endl;
			mins = min(mins, abs(a[i]-a[i-j])+dp[i-j]);
			j++;
		}
		dp[i] = mins;
	}
	cout << dp[n-1] << endl;
	return 0;
}

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


const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll 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 {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if(!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if(t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

mint combination(ll n, ll k) {
    mint r = 1;
    for(ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

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

    mint all = 2;
    all = all.pow(n) - 1;
    all -= combination(n, a);
    all -= combination(n, b);
    cout << all.x << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    ll ans = 0;
    cin>>n;
    set<string> ss[5];
    rep(i,n){
        string s;
        cin>>s;
        if(s[0]=='M') ss[0].insert(s);
        if(s[0]=='A') ss[1].insert(s);
        if(s[0]=='R') ss[2].insert(s);
        if(s[0]=='C') ss[3].insert(s);
        if(s[0]=='H') ss[4].insert(s);
    }
//    int ans = 0;
    rep(i,5)for(int j = i+1; j< 5;j++)for(int k = j+1; k<5;k++){
        ans += ss[i].size()*ss[j].size()*ss[k].size();
    }
    cout<< ans << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,M,n;
  cin>>N>>M>>n;
  vector<int> A(N);
  A[0]=n/2;
  int k=0;
  for(int i=n/2;i%2==0;i/=2)
    k++;
  for(int i=1;i<N;i++){
    cin>>A[i];
    A[i]/=2;
    int l=0;
    for(int j=A[i];j%2==0;j/=2){
      l++;
    }
    if(k!=l){
      cout<<0<<endl;
      return 0;
    }
  }
  k=A[0];
  for(int i:A){
    k=k/__gcd(k,i)*(i);
    if(k>M){
      cout<<0<<endl;
      return 0;
    }
  }
  cout<<(M+k)/k/2<<endl;
}

Measured memory_bytes: 4052
import scala.math

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  def divisors(n: Int): List[Int] =
    for (i <- (1 to n).toList if n % i == 0) yield i
  var n = sc.nextInt()
  var s = Array.fill(n)(sc.next())
  var ans = Array.fill(4)(0)
  for(i <- 0 until n){
    if (s(i)=="AC") ans(0)+=1
    if (s(i)=="WA") ans(1)+=1
    if (s(i)=="TLE") ans(2)+=1
    if (s(i)=="RE") ans(3)+=1
  }
  println("AC x " + ans(0).toString)
  println("WA x " + ans(1).toString)
  println("TLE x " + ans(2).toString)
  println("RE x " + ans(3).toString)
}


Measured memory_bytes: 63128
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    string t;
    cin >> t;
    llint ans = 0;
    REP(i, pow(2, t.size()-1)){
        int x = i;
        int ln = 1;
        string s = t;
        REP(i, t.size()-1){
            if(x%2){
                ans += stoll(s.substr(t.size()-1-i, ln));
                //cout << s.substr(t.size()-1-i, ln) << "\n";
                s = s.substr(0, t.size()-1-i);
                ln = 1;
            }else{
                ln++;
            }
            x = x >> 1;
        }
        if(s.size() > 0) ans += stoll(s);
        //cout << s << "\n";
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int a[100001];
int b[100001];
vector<int>G[100001];
int color[100001];
typedef pair<int,int> P;
int cc[2];
int main(){
    cin>>N;
    REP(i,N-1){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    REP(i,N){
        color[i]=-1;
    }
    color[0]=0;
    color[N-1]=1;
    queue<P>que;
    que.push(P(0,0));
    que.push(P(N-1,1));
    cc[0]=cc[1]=1;
    while(!que.empty()){
       P p=que.front();que.pop();
       int v=p.first;
       int c=p.second;
       REP(i,G[v].size()){
           if(color[G[v][i]]==-1){
              color[G[v][i]]=c;
              que.push(P(G[v][i],c));
              cc[c]++;
           }
       }
    }
    if(cc[0]>cc[1]){
       cout<<"Fennec"<<endl;
    }else{
       cout<<"Snuke"<<endl;
    }
    return(0);
}

Measured memory_bytes: 7168
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n: usize = read_as_vec()[0];
    let mut a: Vec<usize> = read_as_vec();
    let mut b: Vec<usize> = read_as_vec();
    let num_monsters: usize = a.iter().sum();
    for i in 0..n{
        if b[i] < a[i]{
            a[i] -= b[i];
            b[i] = 0;
        }else{ //a[i] <= b[i]
            b[i] -= a[i];
            a[i] = 0;
            if a[i+1] > b[i]{
                a[i+1] -= b[i];
                b[i] = 0;
            }else{
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
    }

    println!("{}", num_monsters - a.into_iter().sum::<usize>());
}


Measured memory_bytes: 10492
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A+B <= C-1){
      cout << A+2*B+1;
    }else{
      cout << B+C;
    }
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
S = gets.split('')
DIRECTIONS = []

S.each do |s|
 DIRECTIONS << (s == "W")
end

WEST_SIZE = DIRECTIONS.select{|e| e}.size

seen_wests = 0
m = N
N.times do |n|
 left = seen_wests
 seen_wests +=1 if DIRECTIONS[n]
 right = (N - n - 1) - (WEST_SIZE - seen_wests)
 m = [m, left + right].min
end

puts m


Measured memory_bytes: 31876
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) FOR(i,0,n)
 
int main(){
	
	string s;cin >> s;
	bool ok = false;
	
	rep(i,s.size())
	{
		if(s[i] == 'C') ok = true;
		
		if(ok and s[i]=='F')
		{
			cout << "Yes" << endl;
			return 0;
		}
		
	}
		
	cout << "No" << endl;
}

//cout << ans << endl;

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

int main(){
  int x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a),q(b);
  priority_queue<int> r;
  for (int i = 0; i < a; i++) cin >> p[i];
  for (int i = 0; i < b; i++) cin >> q[i];
  for (int i = 0; i < c; i++){
    int ri;
    cin >> ri;
    r.push(ri);
  }

  sort(p.begin(),p.end());
  sort(q.begin(),q.end());
  reverse(p.begin(),p.end());
  reverse(q.begin(),q.end());

  vector<int> anss;
  long long ans = 0;
  for (int i = 0; i < x; i++){
    anss.push_back(p[i]);
    ans+=p[i];
  }
  for (int i = 0; i < y; i++){
    anss.push_back(q[i]);
    ans+=q[i];
  }
  sort(anss.begin(),anss.end());
  
  for (int i = 0; i < x+y; i++)
  {
    if(r.empty()) break;
    int mu = r.top();
    r.pop();
    if(anss[i]<mu){
      ans-=anss[i];
      ans+=mu;
    }
    else break;
  }
  cout << ans << endl;  
}

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

int main()
{
    string w;
    cin >> w;
    int v[26] = {};
    for(auto c : w){
        v[c-'a']++;
    }
    for(auto a: v){
        if(a%2 != 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



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

int gcd(int a, int b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}

int main() {
	int N;
	cin >> N;
	vector<ll> A(N, 0);
	repeat(i, N) {
		cin >> A[i];
	}

	int result = A[0];
	for(int i = 1; i < A.size(); i++) {
		result = gcd(result, A[i]);
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d",&a);
  for(int i=a; 0<a; i--){
    b=0;
    for(int j=1; j*j<=i; j++){
      if(j*j==i){b=1;}
    }
    if(b){printf("%d",i);break;}
  }
  return 0;}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i < N+1; i += 2) {
    int count = 0;
    for (int j = 1; j < i+1; j += 2) {
      if (i % j == 0)
        count++;
    }
    if (count == 8)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

ll n, k;
int a[222222], b[222222];

main(){
    scanf("%lld%lld", &n, &k);
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]); 
        a[i]--;
    }
    int ans = 0;
    while(k){
        if(k & 1){
            ans = a[ans];
        }
        for(int i=0; i<n; i++)b[i] = a[a[i]];
        for(int i=0; i<n; i++)a[i] = b[i];
        k >>= 1;
    }
    printf("%d\n", ++ans);
    return 0;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, ans=1, tmp=1;
/*
int LIS(const vector<long long> &a) {
    int N = (int)a.size();
    vector<long long> dp(N, INF);
    for (int i = 0; i < N; ++i) {
        // dp[k] >= a[i] となる最小のイテレータを見つける
        auto it = lower_bound(dp.begin(), dp.end(), a[i]);

        // そこを a[i] で書き換える
        *it = a[i];
    }

    // dp[k] < INF となる最大の k に対して k+1 が答え
    // それは dp[k] >= INF となる最小の k に一致する
    return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}
*/
signed main() {
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        a--;
        A[a] = i;
    }
    for(int i=1;i<N;i++) {
        if(A[i-1]<A[i]) {
            tmp++;
        }
        else {
            tmp = 1;
        }
        ans = max(ans,tmp);
    }
    cout << N-ans << endl;
}   

Measured memory_bytes: 4844
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int d=sc.nextInt();

    int min1=Math.min(a,b);
    int min2=Math.min(c,d);

    System.out.println(min1+min2);
  }
}


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

using namespace std;

int64_t gcd(int64_t a, int64_t b) {
    if (a % b == 0)
        return (b);
    return (gcd(b, a % b));
}

int main(void) {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    int64_t maxA = 0;
    for (int64_t i = 0; i < N; ++i) {
        cin >> A[i];
        if (A[i] > maxA)
            maxA = A[i];
    }
    vector<int64_t> D(maxA + 1, -1);
    vector<int64_t> primes;
    for (int64_t i = 2; i <= maxA; ++i) {
        int64_t can_div = i;
        for (auto p : primes) {
            if (p * p > i) {
                break;
            }
            if (i % p == 0) {
                can_div = p;
                break;
            }
        }
        if (can_div == i) {
            primes.push_back(i);
        }
        D[i] = can_div;
    }

    vector<int64_t> seen(maxA + 1, -1);
    for (int i=0; i<N; ++i) {
        const int64_t ORIGA = i;
        auto a = A[i];

        while (a != 1) {
            int64_t p = D[a];
            if ((seen[p] != -1) && (seen[p] != ORIGA)) {
                int64_t gcd_ret = A[0];
                for(int64_t i=1; i<N; ++i) {
                    gcd_ret = gcd(gcd_ret, A[i]);
                }
                if(gcd_ret == 1) {
                    cout << "setwise coprime" << endl;
                } else {
                    cout << "not coprime" << endl;
                }
                exit(0);
            }
            seen[p] = ORIGA;
            a /= p;
        }
    }

    cout << "pairwise coprime" << endl;
    return 0;
}

Measured memory_bytes: 27792
l[4],r[4],i;main(){float a,b;for(;~scanf("%f%f",&a,&b);){l[a<0.2?3:a<0.6?2:a<1.1?1:0]++;r[b<0.2?3:b<0.6?2:b<1.1?1:0]++;}for(;i<4;i++){printf("%d %d\n",l[i],r[i]);}exit(0);}

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

int main()
{
  int m,n;
  cin>>m>>n;
  const int mod=1e9+7;
  unsigned long long dp[m+1][n+1];
  memset(dp,0,sizeof(dp));
  char k;
  dp[1][1]=1;
  for(int i=0;i<m;i++)
  {
    for(int j=0;j<n;j++)
    {
      cin>>k;
      if(i==0&&j==0)
      continue;
      if(k=='.')
      dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j];
      else
      dp[i+1][j+1]=0;
      dp[i+1][j+1]%=mod;
    }
  }
  dp[m][n]=dp[m][n]%mod;
  cout<<dp[m][n]<<endl;
  return 0;
}


Measured memory_bytes: 8064
#include<cstdio>
#include<algorithm>
using namespace std;
int ans = 1, n, k; 
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++)
		ans += min(ans, k);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    ll V, E;
    cin >> V >> E;
    vvll dist(V, vll(V, INF));
    rep(i, E) {
        ll s, t, d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }
    rep(i, V) dist[i][i] = 0;

    rep(k, V) rep(i, V) rep(j, V) {
        if (dist[i][k] == INF || dist[k][j] == INF) continue;
        chmin(dist[i][j], dist[i][k] + dist[k][j]);
    }

    bool ng = false;
    rep(i, V) if(dist[i][i] < 0) ng = true;

    if(ng) cout << "NEGATIVE CYCLE" << endl;
    else {
        rep(i, V) {
            rep(j, V) {
                if(dist[i][j] == INF) cout << "INF";
                else cout << dist[i][j];
                if(j != V-1) cout << " ";
            }
            cout << endl;
        }
    }
}



Measured memory_bytes: 3256
//file_name:ABC69_C.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    ll a[n] = {};
    int count[3]={};
    rep(i,n){
        scanf("%lld",&a[i]);
        if(a[i]%2==1){
            count[0]++;
        }else if(a[i]%4==0){
            count[2]++;
        }else{
            count[1]++;
        }
    }



    if(count[0]==0){
        puts("Yes");
    }else{
        if(count[2]==0){
            puts("No");
        }else{
            if(count[2]+1<count[0]){
                puts("No");
            }else if(count[2]+1==count[0]&&count[1]!=0){
                puts("No");
            }else{
                puts("Yes");
            }
        }
    }

    return 0;
}



Measured memory_bytes: 1024
N, M = map(int, input().split())
A = [[ch for ch in input()] for _ in range(N)]
B = [[ch for ch in input()] for _ in range(M)]
for ai in range(len(A)-len(B)+1):
    for aj in range(len(A)-len(B)+1):
        trimmed=[]
        for i_trimmer in range(ai,ai+len(B)):
            line=[]
            for j_trimmer in range(aj,aj+len(B)):
                line.append(A[i_trimmer][j_trimmer])
            trimmed.append(line)
        if trimmed==B:
            print('Yes')
            exit(0)

print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;

    int digits = 0;
    while (N / (int)(pow(K, digits + 1)) != 0)
    {
        digits += 1;
    }

    cout << digits + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
"use strict";

function main(input) {
  input = input.trim().split("\n");
  const line_one = parseInt(input[0]);

  let AC = 0;
  let WA = 0;
  let TLE = 0;
  let RE = 0;

  for (let i = 1; i <= line_one; i++) {
    if (input[i] === "AC") AC++;
    if (input[i] === "WA") WA++;
    if (input[i] === "TLE") TLE++;
    if (input[i] === "RE") RE++;
  }

  console.log(`AC x ${AC}`);
  console.log(`WA x ${WA}`);
  console.log(`TLE x ${TLE}`);
  console.log(`RE x ${RE}`);
}

function numberSort(array) {
  array.sort(f);
  return array;
}

var f = function (a, b) {
  return a - b;
};

main(require("fs").readFileSync("/dev/stdin", "utf-8"));


Measured memory_bytes: 37228
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int main(){
  ll x,y;cin>>x>>y;
  int ans = 0;
  while(x <= y){
    ans++;
    x *= 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
MOD = 10**9 + 7
n, m = map(int, input().split())

ok = [True] * (n+1)
for i in range(m):
    a = int(input())
    ok[a] = False

dp = [0] * (n+1)
dp[0] = 1
if ok[1]: dp[1] = 1

for i in range(2, n+1):
    if(ok[i-1]): dp[i] += dp[i-1]
    if(ok[i-2]): dp[i] += dp[i-2]
    dp[i] %= MOD

print(dp[n])



Measured memory_bytes: 13336
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        ll L;
        cin >> N >> L;
        vector<string> S(N);
        rep(i, 0, N) cin >> S[i];

        sort(all(S));
        string ans;
        rep(i, 0, N) ans += S[i];
        cout << ans << endl;
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    return arr


n,k = get_nums_l()
MOD = 10**9+7

ans = 0
count = [0] * (k+1)
for x in range(k, 0, -1):
    count[x] = pow((k//x),n,MOD)

    for y in range(x*2, k+1, x):
        count[x] -= count[y]

print(sum([ x*i for i,x in enumerate(count) ]) % MOD)


Measured memory_bytes: 81908
#include <stdio.h>

int main(void)
{
	int i;
	int number,count=0,out=0;
	int stack[20],hyouji[20];
	
	while(scanf("%d",&number)!=EOF)
	{
		if(number!=0)
		{
			stack[count]=number;
			count++;
		}
		else
		{
			count--;
			printf("%d\n",stack[count]);
			out++;
		}
	}
	

	
	
	return 0;
}

Measured memory_bytes: 596