akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include<cstdio>
// #include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007
#define MOD2 1000000014000000049LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;

template<int N, int M>
struct ModFact {
    int inv[N+1];
    int fact[N+1];
    int ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        ll f = 1;
        fact[0] = f;
        for (int i = 0; i < N; i++) {
            f = f*(i+1)%M;
            fact[i+1] = f;
        }
        f = power(f, M-2);
        ifact[N] = f;
        for (int i = N-1; i >= 0; i--) {
            f = f*(i+1)%M;
            ifact[i] = f;
        }
        for (int i = 0; i < N; i++) {
            f = ll(fact[i])*ll(ifact[i+1])%M;
            inv[i] = f;
        }
    }
    constexpr ll power(ll a, ll b) {
        ll r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
	int operator[](int n) {
		return inv[n];
	}
};

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ModFact<100000, MOD> fact;

int main() {
    ll ans = 0, d;
    int a, N, prev, now;
    N = getint();
    prev = getint();
    REP(i, N-1) {
        now = getint();
        d = now - prev;
        prev = now;
        a = (a + fact[i]) % MOD;
        ans += a * d % MOD;
        // a += fact.inv[i+1];
        // if(a > MOD) a -= MOD;
        // ans += a * d;
        // if(ans > MOD2) ans -= MOD2;
    }
    printf("%lld\n", ((ans%MOD)*fact.fact[N-1])%MOD);
	return 0;
}


Measured memory_bytes: 1408
import Foundation

/*
// 1
let N = Int(readLine()!)!

// 1 2
let split = readLine()!.componentsSeparatedByString(" ")
let N = Int(split[0])!
let S = Int(split[1])!

// 1 2 3 4 5
let array = readLine()!.componentsSeparatedByString(" ").map { Int($0)! }
*/

let N = Double(readLine()!)!
print((N / 3) * (N / 3) * (N / 3))

Measured memory_bytes: 4468
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[1000005];
bool bo;
long long ji;
int main(){
	scanf("%s",&s);
	long long len=strlen(s);
	for(long long i=0;i<len-1;i++){
		if(s[i]!=s[i+1])bo=1;
	}
	if(bo=1){
		if(s[0]!=s[len-1])
			ji=len-2;
		else ji=len-3;
	}
	else ji=0;
	if(ji%2==1)cout<<"First";
	else cout<<"Second";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  map<int, int> a, b;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if( i%2 == 0 ) a[tmp]++;
    else b[tmp]++;
  }
  pair<int, int> a1, a2, b1, b2;
  a1 = a2 = b1 = b2 = make_pair(-1, 0);
  for (auto itr = a.begin(); itr != a.end(); itr++) {
    if( a1.second > itr->second && itr->second > a2.second) {
      a2 = make_pair(itr->first, itr->second);
    }
    else if( a1.second <= itr->second ) {
      a2 = a1;
      a1 = make_pair(itr->first, itr->second);
    }
  }
  for (auto itr = b.begin(); itr != b.end(); itr++) {
    if( b1.second > itr->second && itr->second > b2.second) {
      b2 = make_pair(itr->first, itr->second);
    }
    else if( b1.second <= itr->second ) {
      b2 = b1;
      b1 = make_pair(itr->first, itr->second);
    }
  }
  if( a1.first != b1.first ) dump(n/2-a1.second+n/2-b1.second);
  else {
    int r1 = n-a1.second-b2.second;
    int r2 = n-a2.second-b1.second;
    dump(min(r1, r2));
  }
  return 0;
}


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

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

const int MOD = 1e9+7;
const int MAX = 1e5+7;

int main(){
	int n, k; cin >> n >> k;
	vi v(n); FOR(i, n) cin >> v[i];

	sort(all(v));

	ll ans = 1;
	if(v[0] >= 0){
		FOR(i, k){
			ans = ans * v[n-i-1] % MOD;
		}
	}else if(v[n-1] <= 0){
		if(k%2){
			FOR(i, k) ans = ans * v[n-i-1] % MOD;
		}else{
			FOR(i, k) ans = ans * v[i] % MOD;
		}
	}else{
		int l = 0, r = n-1;

		if(k%2){
			ans = ans * v[r] % MOD;
			r--;
			k--;
		}

		while(k){
			ll a1, a2;
			a1 = 1LL * v[l] * v[l+1];
			a2 = 1LL * v[r] * v[r-1];

			if(a1 > a2){
				a1 %= MOD;
				ans = ans * a1 % MOD;
				l+=2;
			}else{
				a2 %= MOD;
				ans = ans * a2 % MOD;
				r-=2;
			}

			k-=2;
		}
	}

	if(ans < 0) ans += MOD;
	
	cout << ans << endl;

	return 0;
}


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

int main() {
int n,m;
cin >> n >> m;
vector<int> a(n);
for(int i = 0;i<n;i++) cin >> a[i];
int s = 0;
for(int i=0;i<n;i++) s += a[i];
int cnt = 0;
for(int i = 0;i<n;i++){
	if(a[i]*(4*m) >= s) cnt++;
}
if(cnt >= m){
	cout << "Yes" << endl;
} else {
	cout << "No" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include<iostream>

const static int INF = 1001001001;

int main(void){
    int h, n;
    std::cin >> h >> n;
    int dp[n+1][h+1];

    for(int i = 0; i < n+1; i++){
	for(int j = 0; j < h+1; j++){
	    dp[i][j] = INF;
	}
    }
    for(int i = 0; i < n+1; i++){
	dp[i][0] = 0;
    }

    for(int i = 0; i < n; i++){
	int a, b;
	std::cin >> a >> b;
	for(int j = 0; j <= h; j++){
	    dp[i+1][j] = dp[i][j];
	}
	for(int j = 0; j <= h; j++){
	    int nj = std::min(j + a, h);
	    dp[i+1][nj] = std::min(dp[i+1][nj], dp[i+1][j] + b);
	}
    }
    std::cout << dp[n][h] << std::endl;
    return 0;
}



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


int main(){



  int64_t x;
  cin>>x;

  int64_t rootx=0;
  while (rootx*rootx<=x){
    rootx++;
  }
  
  rootx--;
  

  
  vector<int64_t> factors(0);
  

  
  
  
  
  
  for (int64_t i=1;i<=rootx;i++){
    if (x%i==0){
      factors.push_back(i);
      if (i!=x/i){
        factors.push_back(x/i);
      }
    }
  }
  

  
  
  
  int64_t a=1;
  int64_t b=0;
  
  
  int64_t size=int64_t(factors.size());
  for (int64_t i=0;i<size;i++){
    int64_t d=factors.at(size-1-i);
    
    int64_t flag=1;
    
    int64_t tmp=0;
    
    
    
    while (tmp-d<120 ){
      if (tmp*tmp*tmp*tmp*tmp-(tmp-d)*(tmp-d)*(tmp-d)*(tmp-d)*(tmp-d)==x){
        a=tmp;
        b=a-d;
        flag=0;
        break;
      }
      
      else {
        tmp++;
      }
    }
    
    if (flag==0){
      break;
    }
    
  }
  
  
  cout<<a<<" "<<b<<endl;
  
  
  
  
  
    
      
      

  
  
  
    
    
    
        
      
    
  
  
  
  
    
  
}

Measured memory_bytes: 3580
N, M, Q = map(int, input().split())
mem = [[0 for _ in range(N)] for _ in range(N)]

for _ in range(M):
    L, R = map(int, input().split())
    mem[L-1][R-1] += 1

for L in range(N):
    for R in range(1, N):
        mem[L][R] += mem[L][R-1]

for R in range(N):
    for L in range(1, N):
        mem[L][R] += mem[L-1][R]

res = []
for _ in range(Q):
    QL, QR = map(int, input().split())
    if QL == 1:
        r = mem[QR-1][QR-1]
    else:
        r = mem[QR-1][QR-1] - mem[QL-2][QR-1]
    res.append(r)

for r in res:
    print(r)

Measured memory_bytes: 22612
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto N = RD;
	auto s = new string[](N);
	auto t = new long[](N);
	foreach (i; 0..N)
	{
		s[i] = RD!string;
		t[i] = RD;
	}
	auto X = RD!string;

	long ans;
	bool f;
	foreach (i; 0..N)
	{
		if (f)
		{
			ans += t[i];
		}
		else
		{
			if (s[i] == X)
			{
				f = true;
			}
		}
	}
	
	writeln(ans);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int H,W;cin >> H >> W;
  rep(y,H) rep(x,W){
    string s;cin >> s;
    if(s=="snuke"){
      cout << char(x+'A');
      cout << y+1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, K, A[1 << 18], F[1 << 18];

long long getans(long long rev) {
	long long asc = 0;
	for (int i = 1; i <= N; i++) {
		long long goal = rev / F[N + 1 - i];
		asc += max(0LL, A[i] - goal);
	}
	return asc;
}

int main() {
	scanf("%lld%lld", &N, &K);
	for (int i = 1; i <= N; i++) scanf("%lld", &A[i]);
	for (int i = 1; i <= N; i++) scanf("%lld", &F[i]);
	sort(A + 1, A + N + 1);
	sort(F + 1, F + N + 1);

	long long cl = 0, cr = (1LL << 40), cm, maxn = (1LL << 60);
	for (int i = 0; i < 67; i++) {
		cm = (cl + cr) / 2;
		long long val = getans(cm);
		if (val <= K) { cr = cm; maxn = min(maxn, cm); }
		else cl = cm;
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
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();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N; cin >> N;
    string S; cin >> S;
    string A = S.substr(0,N), B = S.substr(N,N);
    REVERSE(B);

    vector<pair<string,string>> v;
    REP(i,1<<N){
        string s="", t="";
        REP(j,N) if((i>>j) & 1) s += A[j]; else t += A[j];
        v.emplace_back(s,t);
    }

    map<pair<string,string>, ll> m;
    REP(i,1<<N){
        string s="", t="";
        REP(j,N) if((i>>j) & 1) s += B[j]; else t += B[j];
        auto p = make_pair(s,t);
        if(m.find(p) != m.end()) m[p]++;
        else m[p] = 1;
    }

    ll ans = 0;
    for(auto p : v){
        string r = p.first, b = p.second;
        auto s = make_pair(b,r);
        if(m.find(s) != m.end()) ans += m[s];
    }
    cout << ans << en;
    return 0;
}

Measured memory_bytes: 79596
#D
import queue
H,W=map(int,input().split())
P=[0 for i in range(H)]
for i in range(H):
    P[i]=str(input())
ans=0
for i in range(H*W):
    s=(i//W,i%W)
    if P[s[0]][s[1]]=="#":
        continue
    st=queue.Queue()
    st.put(s)
    log=[[-1 for i in range(W)] for j in range(H)]
    log[s[0]][s[1]]=0
    while not st.empty():
        y,x=st.get()
        for z,w in [(y+1,x),(y-1,x),(y,x+1),(y,x-1)]:
            if 0>z or 0>w:
                continue
            elif z>=H or w>=W:
                continue
            elif P[z][w]=="." and log[z][w]==-1:
                st.put((z,w))
                log[z][w]=log[y][x]+1
                ans=max(ans,log[z][w])
print(ans)

Measured memory_bytes: 56660
import math

n = int(input())
a_list = list(map(int, input().split()))

a_max = (10**6)+1
hist = [0] * a_max
for a in a_list:
    hist[a] += 1

pairwise = True
for i in range(2, a_max, 1):
    count = 0
    for j in range(i, a_max, i):
        count += hist[j]

    if count > 1:
        pairwise = False

if pairwise:
    print('pairwise coprime')
else:
    setwise = True
    g = a_list[0]
    for a in a_list:
        g = math.gcd(g, a)
    if g > 1:
        setwise = False

    if setwise:
        print('setwise coprime')
    else:
        print('not coprime')


Measured memory_bytes: 212904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  int n;cin>>n;
  int sum=0;
  rep(i,n){
   int l,r;cin>>l>>r;
    sum+=r-l+1;
  }
  cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
  int k, q;
  int d[5000];
  
  scanf("%d %d", &k, &q);
  
  for (int i = 0; i < k; i++) scanf("%d", d + i);
  
  for (int i = 0; i < q; i++) {
    int n, x, m;
    scanf("%d %d %d", &n, &x, &m);
    long long dif = x % m;
    for (int j = 0; j < k; j++) {
      long long M = (d[j] % m == 0 ? m : d[j] % m);
      dif += M * ((n - 1) / k + (j < (n - 1) % k));
    }
    printf("%d\n", n - 1 - dif / m);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;


signed main() {
  ll k;
  string s;
  cin >> k >> s;
  if (s.size() > k) {
    s = s.substr(0, k) + "...";
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
using namespace std;
typedef long long int LLI;

struct traveling{
	LLI t;
	LLI x;
	LLI y;
};

string solve(LLI & n)
{
	traveling a, b;
	LLI distance, time;
	cin >> a.t >> a.x >> a.y;
	
	if( a.t < a.x + a.y )
		return "No";

	for(int i = 1; i < n; i++)
	{
		cin >> b.t >> b.x >> b.y;
		distance = abs( a.x - b.x ) + abs( a.y - b.y );
		time = b.t - a.t;
		
		if( distance > time )
			return "No";
		else if( ( time - distance ) % 2 == 1 )
			return "No";
		a = b;
	}
	return "Yes";
}

int main()
{
	LLI n;
	cin >> n;
	cout << solve(n);
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)

#define ll long long

int main() {

  ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // freopen("input.in", "r", stdin);
    ll a, b,c,d;
    cin>>a>>b>>c>>d;

    ll max1 = a*c;
    ll max2 = a*d;
    ll max3 = b*c;
    ll max4 = b*d;

    cout<<max(max(max1, max2), max(max3, max4))<<"\n";


    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define enter "\n"

typedef long long ll;


int abc102_c(){
    int n;
    cin >> n;
    vector<int> a;
    REP(i,n){
        int tmp;
        cin >> tmp;
        a.push_back(tmp-i-1);
    }
    ll ans = 0;
    
    //処理
    sort(a.begin(),a.end());
    ll med;
    if(n%2==1) med = a[(n-1)/2];
    else med = a[n/2];
    REP(i,n){
        ans += abs(med-a[i]);
    }
    
    //出力
    cout << ans << enter;
    return 0;
}

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


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

typedef complex<double>Point;

struct Segment{
    Point p1,p2;
    Segment(const Point &p1=Point(),const Point &p2=Point()):p1(p1),p2(p2){}
};

struct Circle{
    Point p;
    double r;
    Circle(const Point &p=Point(),double r=0.0):p(p),r(r){}
};

typedef Point Vector;
typedef Segment Line;
typedef vector<Point>Polygon;

const double PI=acos(-1);
const double EPS=1e-8;
const double INF=1e16;

inline double square(double a){return a*a;}
inline double norm(const Point &a){return square(a.real())+square(a.imag());}
inline double dot(const Point &a,const Point &b){return (conj(a)*b).real();}
inline double cross(const Point &a,const Point &b){return (conj(a)*b).imag();}
inline double toDeg(double t){return t/PI*180.0;}
inline double toRad(double t){return t/180.0*t;}
#define equals(a,b) (fabs((a)-(b))<EPS)

bool isOrthogonal(Vector a,Vector b){
    return equals(dot(a,b),0.0);
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
    return isOrthogonal(a1-a2,b1-b2);
}

bool isOrthogonal(Segment s1,Segment s2){
    return isOrthogonal(s1.p1-s1.p2,s2.p1-s2.p2);
}

bool isParallel(Vector a,Vector b){
    return equals(cross(a,b),0.0);
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
    return isParallel(a1-a2,b1-b2);
}

bool isParallel(Segment s1,Segment s2){
    return isParallel(s1.p1-s1.p2,s2.p1-s2.p2);
}

Point project(Segment s,Point p){
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/norm(base);
    return s.p1+base*r;
}

Point reflection(Segment s,Point p){
    return p+(project(s,p)-p)*2.0;
}
void getPoint(Point &p){
    double x,y;
    scanf("%lf%lf",&x,&y);
    p=Point(x,y);
}

int main(){
    Segment s;
    getPoint(s.p1);
    getPoint(s.p2);

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

    while(q--){
        Point p;
        getPoint(p);\
        Vector b=reflection(s,p);
        printf("%.20lf %.20lf\n",b.real(),b.imag());
    }
    return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

class UnionFind {
private:
    int n;
    vector<int> uni;
public:
    UnionFind(int _n) {
        n = _n;
        uni.clear();
        uni.resize(n, -1);
    }
    int root(int x) {
        if (uni[x] < 0) return x;
        return uni[x] = root(uni[x]);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (uni[x] > uni[y]) swap(x, y);
        uni[x] += uni[y];
        uni[y] = x;
    }
    void print() {
        for (auto x : uni) cout << x << " ";
        cout << endl;
    }
};

template <typename T>
struct edge {
    int from, to;
    T cost;
    edge(){}
    edge(int _from, int _to, T _cost) : from(_from), to(_to), cost(_cost) {}
    bool operator< (const edge& e) const {
        return cost == e.cost ? (from == e.from ? to < e.to : from < e.from) : cost < e.cost;
    }
};

template <typename T>
class Kruskal {
private:
    int n;
    vector<edge<T>> edges;
    UnionFind uf;
public:
    Kruskal(int _n) : n(_n), uf(UnionFind(n)) {}
    void addEdge(int _from, int _to, T _cost) {
        edges.emplace_back(_from, _to, _cost);
    }
    T calc() {
        sort(all(edges));
        T res = 0;
        for (auto &e : edges) {
            if (!uf.same(e.from, e.to)) {
                uf.unite(e.from, e.to);
                res += e.cost;
            }
        }
        return res;
    }
};

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

    int n;
    cin >> n;
    Kruskal<double> kr(n);
    rep(i, n) {
        rep(j, n) {
            double c;
            cin >> c;
            if (c == -1) c = 1e9;
            kr.addEdge(i, j, c);
        }
    }
    cout << (int)kr.calc() << endl;
}

Measured memory_bytes: 3468
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int dp[] = new int[100010];

		for (int i = 0; i < m; i++) {
			int a = Integer.parseInt(br.readLine());
			dp[a] = Integer.MAX_VALUE;
		}

		dp[0] = 1;
		if (dp[1] == Integer.MAX_VALUE) {
			dp[1] = 0;
		} else {
			dp[1] = 1;
		}

		for (int i = 2; i <= n; i++) {
			if (dp[i] == Integer.MAX_VALUE) {
				dp[i] = 0;
			} else {
				dp[i] = dp[i - 1] % 1000000007 + dp[i - 2] % 1000000007;
			}
		}

		System.out.println(dp[n] % 1000000007);
	}
}

Measured memory_bytes: 30676
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
    int x,a;
    scanf("%d%d",&x,&a);
    printf("%d\n",x<a?0:10);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int sum() { return 0; }

template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }





int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    std::vector<int> v(n);
    std::map<int, int> mp;
    ll int sum = 0;
    REP(i,n){
         cin>>v[i];
         mp[v[i]]++;
         sum += v[i];
     }
     int q;cin>>q;
     int a[q+2] , b[q+2];
     for (int i = 0; i < q; ++i)
     {
         cin>>a[i]>>b[i];
     }
     for (int i = 0; i < q; ++i)
     {
         //int a,b;cin>>a>>b;
         ll int cnt = mp[a[i]];
         sum += (cnt * (b[i]-a[i]));
         mp[a[i]] = 0;
         mp[b[i]] += cnt;
         cout<<sum<<"\n";

     }
     return 0;
 }


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

using namespace std;

int main() 
{
  int n;
  cin >> n;
  int d[n],dan=1;
  for(int i=0; i<n; i++)
    cin >> d[i];

  sort(d,d+n);

  for(int i=n-1; 0<i; i--)
  {
    if( d[i-1] < d[i] )
      dan++;
  }

  cout << dan << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10e+6

using namespace std;

int main(){
    int n;
    cin >>n;
    cout << 180*(n-2) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] color = new int[8];
    int min =0, max =0, expert =0;
    for (int i =0; i<N; i++) {
      int x = sc.nextInt();
      if (x >= 3200) {
        expert++;
      } else if (x >= 2800) {
        color[7]++;
      } else if (x >= 2400) {
        color[6]++;
      } else if (x >= 2000) {
        color[5]++;
      } else if (x >= 1600) {
        color[4]++;
      } else if (x >= 1200) {
        color[3]++;
      } else if (x >= 800) {
        color[2]++;
      } else if (x >= 400) {
        color[1]++;
      } else {
        color[0]++;
      }
    }
    for (int i =0; i<8; i++) {
      if (color[i] != 0) min++;
    }
    max = min + expert;
    min = Math.max(min, 1);
    System.out.println(min + " " + max);
  }
}

Measured memory_bytes: 21204
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
 
#ifdef LOCAL_ENV
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#else
const bool test = false;
#define dump(x) 
#endif
 
#else
const bool test = false;
#define dump(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
 
template<typename T>
T gcd(T a, T b)
{
  T c;
  while (a != 0) {
    c = a; a = b%a;  b = c;
  }
  return b;
}
 
void solve();
 
class Solver {
public:
  int N;
 
  void solve() {
    int l[100];
    l[0] = 2;
    l[1] = 1;
    rep2(i, 2, 100) {
      l[i] = l[i-1] + l[i-2];
    }
    
    cin >> N;
    cout << l[N] << endl;
  }
};
 
signed main()
{
  srand(time(NULL));
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {    
  //     auto ptr = new Solver();
  //     ptr->solve();
  //     delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'


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

using namespace std;
using ll = long long;

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

int n;
vector<ll> a(3005);
ll dp[3005][3005];

ll rec(int l, int r) {
  if (l == r)
    return 0;

  if (dp[l][r])
    return dp[l][r];

  if ((n - (r - l)) % 2 == 0) {
    dp[l][r] = max(rec(l + 1, r) + a[l], rec(l, r - 1) + a[r - 1]);
  } else {
    dp[l][r] = min(rec(l + 1, r) - a[l], rec(l, r - 1) - a[r - 1]);
  }

  return dp[l][r];
}

int main() {
  cin >> n;
  rep(i, n) cin >> a[i];
  cout << rec(0, n) << endl;
  return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll H, W, N;
    cin >> H >> W >> N;

    vector<ll> a(N);
    rep (i, N) {
        cin >> a[i];
    }

    vector<ll> tmp;
    rep (i, N) {
        rep (j, a[i]) {
            tmp.push_back(i+1);
        }
    }

    vector<vector<ll>> ans(H, vector<ll>(W, 0));

    rep (i, H) {
        if (i%2) {
            rep(j, W) {
                ans[i][W-j-1] = tmp[i*W+j];
            }
        } else {
            rep(j, W) {
                ans[i][j] = tmp[i*W+j];
            }
        }
    }

    rep (i, H) {
        rep (j, W) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int,input().split()))
g = 0
for i in range(N):
  g += A[i]
ans = 10**8
su = 0
for i in range(N):
  su += A[i]
  if abs(g -2*su) < ans:
    ans = abs(g -2*su)
print(ans)

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



// 二部グラフの最大マッチング
struct Biparite_Matching {

    int n;
    vector<vector<int>> g;
    vector<int> match;
    vector<bool> seen;

    Biparite_Matching(int _n) {
        n = _n;
        g.assign(n, vector<int>());
        match.resize(n);
        seen.resize(n);
    }

    // 辺の追加
    void add_edge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }

    bool dfs(int v) {
        seen[v] = true;
        for(int i = 0; i < (int)g[v].size(); i++) {
            int u = g[v][i];
            int w = match[u];
            if(w < 0 || (!seen[w] && dfs(w))) {
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }

    // 最大マッチング数
    int count() {
        int res = 0;
        match.assign(n, -1);
        for(int v = 0; v < n; v++) {
            if(match[v] < 0) {
                seen.assign(n, false);
                if(dfs(v)) res++;
            }
        }
        return res;
    }

};



int main(){
    
    int h, w;
    cin >> h >> w;
    V<string> s(h);
    rep(i,h) cin >> s[i];

    auto make_Id = [&](int i, int j) {
        if(h > w) return h*j+i;
        else return w*i+j;
    };

    auto res_Point = [&](int id) {
        int i = 0, j = 0;
        if(h > w) j = id/h, i = id%h;
        else i = id/w, j = id%w;
        return P(i,j);
    };

    Biparite_Matching bm(h*w);
    rep(i,h)rep(j,w) {
        if(s[i][j] == '#') continue;
        rep(di,4) {
            int ny = i + dy[di];
            int nx = j + dx[di];
            if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
            if(s[ny][nx] == '#') continue;
            bm.add_edge(make_Id(i,j), make_Id(ny,nx));
        }
    }

    auto ans = s;

    int cnt = bm.count();
    rep(i,h)rep(j,w) {
        int id = make_Id(i,j);
        int nid = bm.match[id];
        if(nid < 0) continue;
        P p = res_Point(nid);

        if(i > p.fi) ans[i][j] = '^', ans[p.fi][p.se] = 'v';
        if(i < p.fi) ans[i][j] = 'v', ans[p.fi][p.se] = '^';
        if(j > p.se) ans[i][j] = '<', ans[p.fi][p.se] = '>';
        if(j < p.se) ans[i][j] = '>', ans[p.fi][p.se] = '<';
    }

    cout << cnt << endl;

    rep(i,h) {
        rep(j,w) cout << ans[i][j];
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 4408
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  string s1,s2,s3;
  cin >> s1>> s2>> s3;
  transform(s1.begin(),s1.end(),s1.begin(),::toupper);
  transform(s2.begin(),s2.end(),s2.begin(),::toupper);
  transform(s3.begin(),s3.end(),s3.begin(),::toupper);
  cout << s1[0]<<s2[0]<<s3[0]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n;
  cin >> n;
  vll v(n);
  rep(i, n) cin >> v[i];
  ll ans = 0;
  ll mx = 0;
  rep(i, n) {
    chmax(mx, v[i]);
    ans += max(ll(0), mx - v[i]);
  }
  out(ans);
}
int main(void) { solve(); }

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

using namespace std;

int main()
{
    char a;
    cin >> a;
    if(a == 'A'){
        cout <<"T";
    }
    else if(a == 'T'){
        cout <<"A";
    }
    else if(a == 'G'){
        cout <<"C";
    }
    else if(a == 'C'){
        cout <<"G";
    }
}


Measured memory_bytes: 256
fn read_lines() -> Vec<String> {
    use std::io::Read;

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    return buf.lines().map(|e| e.to_string()).collect::<Vec<_>>();
}

static mut COMP_COUNT: u32 = 0;

fn main() {
    let input = read_lines();
    let n: usize = input[0].parse().unwrap();
    let mut series = input[1].split_whitespace().map(|s| s.parse().unwrap()).collect::<Vec<u32>>();

    merge_sort(&mut series, 0, n);

    println!("{}", series.into_iter().map(|e| format!("{}", e)).collect::<Vec<String>>().join(" "));
    unsafe {
        println!("{}", COMP_COUNT);
    }
}

fn merge_sort(series: &mut Vec<u32>, left: usize, right: usize) {
    if 1 >= right - left {
        // 対象の配列の長さが1以下なら何もしない
    } else {
        let mid = (left + right) / 2;
        merge_sort(series, left, mid);
        merge_sort(series, mid, right);
        merge(series, left, mid, right);
    }
}

fn merge(series: &mut Vec<u32>, left: usize, mid: usize, right: usize) {
    let mut ls = series[left..mid].to_vec();
    ls.push(std::u32::MAX); // 番兵
    let mut rs = series[mid..right].to_vec();
    rs.push(std::u32::MAX); // 番兵

    let mut li = 0;
    let mut ri = 0;
    for i in left..right {
        unsafe {
            COMP_COUNT += 1;
        }
        if ls[li] <= rs[ri] {
            series[i] = ls[li];
            li += 1;
        } else {
            series[i] = rs[ri];
            ri += 1;
        }
    }
}


Measured memory_bytes: 37652
n = int(input())
p = [int(x) for x in input().split(' ')]

count = 0
for i in range(1, n-1):
    if p[i] != max(p[(i-1):(i+2)]) and p[i] != min(p[(i-1):(i+2)]):
        count += 1

print(count)

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

using namespace std;

const int Maxn = 1e5+7;

int n;
int a[Maxn][3];
int dp[Maxn][3];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        for(int j = 0; j < 3; ++j)
            cin >> a[i][j];
    //yesterday play 'k', today play 'j' 
    for(int i = 1; i <= n; ++i)
        for(int j = 0; j < 3; ++j)
            for(int k = 0; k < 3; ++k)
                if(j != k)
                    dp[i][j] = max(dp[i][j], dp[i-1][k]+a[i][j]);
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
    return 0;
}

Measured memory_bytes: 2560
n = int(input())
li = [input() for i in range(n)]

cnt = 0
xa = bx = ba = 0
for i in range(n):
  s = li[i]
  cnt += s.count("AB")
  if s.find("B")==0 and s.rfind("A")==len(s)-1:
    ba += 1
  elif s.find("B") == 0:
    bx += 1
  elif s.rfind("A") == len(s)-1:
    xa += 1

if xa == 0 and bx == 0 and ba != 0:
  print("{}".format(cnt+ba-1))
elif xa == 0 and bx == 0 and ba == 0:
  print("{}".format(cnt))
elif xa == 0 or bx == 0:
  print("{}".format(cnt+ba))
else:
  print("{}".format(cnt+ba+1+min([xa-1,bx-1])))

Measured memory_bytes: 44504
#include<bits/stdc++.h>
#include<chrono>
#include<random>
#define ll long long
#define int ll
#define INF 1e+18
#define EPS 1e-18
#define pii pair<int,int>
#define endl "\n"
#define all(mas) mas.begin(),mas.end()
#define forn(i,n) for(int i = 0; i < n; i++)
#define forn_(i,n) for(int i = n - 1; i >= 0; i--)
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 1e5 + 1;
int a, b, mas[MAXN];

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

	int r, d, x;
	cin >> r >> d >> x;

	forn(i,10) {
		x = max(0ll,r*x - d);
		cout << x << endl;
	}

	return 0;
}

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

int main (void)
{
    int i,k=0;
    char s[11];
    char a[11];
    scanf("%s",a);
    for(i=0;i<strlen(a);i++)
    {
        if(a[i]=='0')
        {
            s[k++]='0';
        }else{
            if(a[i]=='1')
            {
                s[k++]='1';
            }else{
                if(k>0)
                {
                    k--;
                }
            }
        }
    }
    for(i=0;i<k;i++)
    {
        printf("%c",s[i]);
    }
    putchar('\n');
    return 0;
}


Measured memory_bytes: 1592
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    a = input()

    print(a.count('1'))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


const int MAX_N=200010;
int n,dat[4*MAX_N-1];
int Seg_init(int n_){
    n=1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;++i)dat[i]=0;
    return n;
}
int Seg_calc(int a,int b){
    return (a+b)%3;
}
void Seg_update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=Seg_calc(dat[2*k+1],dat[2*k+2]);
    }
}
/*
int Seg_query(int a,int b,int k,int l,int r){
    cout << a MM b MM k MM l MM r << endl;
    //外からはSeg_query(a,b,0,0,n)で呼ぶ
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b)return dat[k];
    int vl=Seg_query(a,b,2*k+1,l,(l+r)/2);
    int vr=Seg_query(a,b,2*k+2,(l+r)/2,r);
    return Seg_calc(vl,vr);
}*/

int Seg_query(int a,int b){
    vector<pair<pair<int,int>,int>> G;
    G.push_back({{0,n},0});
    int R=0;
    
    while(!G.empty()){
        int l=G.back().first.first;
        int r=G.back().first.second;
        int k=G.back().second;
        //cout << l MM r MM k;
        G.pop_back();
        if(r<=a||b<=l)continue;
        if(a<=l&&r<=b){R=Seg_calc(R,dat[k]);continue;}
        G.push_back({{l,(l+r)/2},2*k+1});
        G.push_back({{(l+r)/2,r},2*k+2});
    }
    
    return R;
}

signed main(void){
    string S,T;
    int Q;
    int A[114514],B[114514],C[114514],D[114514];
    int G[114514],H[114514];
    
    cin >> S >> T;
    cin >> Q;
    REP(i,Q){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--;B[i]--;C[i]--;D[i]--;
    }
    
    //Aを1、Bを2、O(=AB)を0と扱う
    
    //Sをセグる
    Seg_init(S.size());
    REP(i,S.size()){
        Seg_update(i,(S[i]=='A'?1:2));
    }
    REP(i,Q){
        G[i]=Seg_query(A[i],B[i]+1);
    }
    //Tをセグる
    Seg_init(T.size());
    REP(i,T.size()){
        Seg_update(i,(T[i]=='A'?1:2));
    }
    REP(i,Q){
        H[i]=Seg_query(C[i],D[i]+1);
    }
    
    //REP(i,Q){cout << G[i] MM H[i] << endl;}
    
    REP(i,Q){
        if(G[i]==H[i]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 10240
#include <stdio.h>

typedef struct {
    char team[22];
    int point;
} DATA;

int main(void)
{
    DATA data[10];
    DATA tmp;
    int win, loose, draw;
    int n;
    int i, j;
    int flag;
    
    flag = 0;
    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%s%d%d%d", data[i].team, &win, &loose, &draw);
            
            data[i].point = win * 3 + draw;
        }
        
        for (i = 0; i < n; i++){
            for (j = 0; j < n - 1; j++){
                if (data[j].point < data[j + 1].point){
                    tmp = data[j];
                    data[j] = data[j + 1];
                    data[j + 1] = tmp;
                }
            }
        }
        
        if (flag == 1){
            printf("\n");
        }
        flag = 1;
        for (i = 0; i < n; i++){
            printf("%s,%d\n", data[i].team, data[i].point);
        }
    }
    return (0);
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 55, M = 1010;

int n;
LL f[N], p[N], x;

void solve()
{
	scanf("%d%lld", &n, &x);
	f[0] = p[0] = 1LL;
	for (int i = 1; i <= n; i ++ ) 
	{
		f[i] = 2 * f[i - 1] + 3LL;
		p[i] = 2 * p[i - 1] + 1LL;
	}	
	
	LL res = 0;
	for (int i = n; i >= 0; i -- )
	{
		if (x == 0) break;
		if (x == f[i])
		{
			res += p[i];
			break;
		}
		if (x == 1) break;

		assert(i > 0);
		if (x <= 1LL + f[i - 1]) x -- ;
		else
		{
			res += 1LL + p[i - 1];
			x -= f[i - 1] + 2LL;
		}
	}
	printf("%lld\n", res);
}

int main()
{
	int T = 1;
	// scanf("%d", &T);
	// cin >> T;
	while (T -- ) solve();
	return 0;
}

Measured memory_bytes: 256