akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  vector<pair<ll,int>> ps;
  for (int t = 0; t < 2; t++) {
    for (int i = 0; i < N; i++) {
      ll a;
      cin >> a;
      ps.emplace_back(a, t);
    }
  }
  sort(ps.begin(), ps.end());
  vector<int> acc(2, 0);
  ll res = 1;
  for (auto p: ps) {
    int t = p.second;
    if (acc[t^1] > 0) {
      res = res * acc[t^1] % MOD;
      --acc[t^1];
    } else {
      ++acc[t];
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 6256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, M; char A[10]; 
	cin >> N >> M; 
	int C[10] = {0,2,5,5,4,5,6,3,7,6}; 
	for(int i = 0; i < M; i++){
		cin >> A[i]; 
	}
	string dp[10010] = {}; bool possible[10010] = {}; 
	possible[0] = true; 
	for(int i = 2; i <= N; i++){
		string tmp[10] = {};
		for(int j = 0; j < M; j++){ 
			if(i - C[A[j] - '0'] >= 0 && possible[i - C[A[j] - '0']]) {
				tmp[j] = A[j] + dp[i - C[A[j] - '0']]; 
				if(tmp[j].size() > 1 && tmp[j].at(0) < tmp[j].at(1)){
					sort(tmp[j].begin(), tmp[j].end(), greater<char>()); 
				}
				possible[i] = true; 
			}
		}
		dp[i] = tmp[0]; 
		for(int k = 1; k < M; k++){
			if(tmp[k].size() > dp[i].size() || (tmp[k].size() == dp[i].size() && tmp[k] >= dp[i]))
				dp[i] = tmp[k]; 
		}
	}
	cout << dp[N] << endl; 
}

Measured memory_bytes: 30592
while True:
    Sa = 1000000
    n = int(input())
    if n == 0:
        break
    Num_lis = list(map(int,input().split()))
    Num_lis = sorted(Num_lis)
    for i in range(n - 1):
        if Num_lis[i + 1] - Num_lis[i] < Sa:
            Sa = Num_lis[i + 1] - Num_lis[i]
    print(Sa)

Measured memory_bytes: 7640
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P; // pair(coordinate, index)

struct Edge {
    ll from, to, cost;
    Edge(){}
    Edge(ll from, ll to, ll cost):from(from),to(to),cost(cost){}
};

bool comp(const Edge &e1, const Edge &e2) {
    return e1.cost<e2.cost;
}

class union_find {
private:
    vector<ll> par;
    vector<ll> ran;
    vector<ll> m_size;
public:
    union_find(int n);
    int find(int x);
    void unite(int x, int y);
    bool same(int x, int y);
    ll size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    iota(par.begin(), par.end(), 0);
    ran.resize(n, 0);
    m_size.resize(n, 1);
};

int union_find::find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (ran[x] < ran[y]) swap(x,y);
    par[y] = x;
    m_size[x] += m_size[y];
    if (ran[x]==ran[y]) ran[x]++;
};

ll union_find::size(int x) {
    return m_size[find(x)];
}

bool union_find::same(int x, int y) {
    return (find(x) == find(y));
};


vector<Edge> g;

int V;

ll kruskal() {
    sort(g.begin(), g.end(), comp);
    union_find uf(V+1);
    ll res = 0ll;
    for (auto &&e: g) {
        if (!uf.same(e.from,e.to)) {
            uf.unite(e.from,e.to);
            res+=e.cost;
        }
    }
    return res;
}

int main(int argc, char const *argv[]) {
    cin>>V;
    vector<P> X, Y;

    rep(i,V) {
        ll x,y; cin>>x>>y;
        X.emplace_back(x,i); Y.emplace_back(y,i);
    }

    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    rep(i,V-1) {
        ll from = X[i].second; ll to = X[i+1].second;
        ll cost = X[i+1].first-X[i].first;
        g.emplace_back(from,to,cost);
        from = Y[i].second; to = Y[i+1].second;
        cost = Y[i+1].first-Y[i].first;
        g.emplace_back(from,to,cost);
    }

    cout << kruskal() << endl;

    return 0;
}

Measured memory_bytes: 13024
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

int n;
map<string, bool> memo;
vector<map<string, long long>> cnt;
long long m = 1e9 + 7;

bool isOk(string src)
{
    if (memo.find(src) != memo.end())
    {
        return memo[src];
    }

    for (size_t i = 0; i < src.length() - 1; i++)
    {
        if (src.find("AGC") != string::npos)
        {
            return memo[src] = false;
        }

        string alt = src;
        alt[i] = src[i + 1];
        alt[i + 1] = src[i];
        if (alt.find("AGC") != string::npos)
        {
            return memo[src] = false;
        }
    }

    return memo[src] = true;
}

long long dfs(int pos, string base)
{
    if (pos == n)
    {
        return 1LL;
    }

    if (cnt[pos].find(base) != cnt[pos].end())
    {
        return cnt[pos][base];
    }

    long long tmp = 0;
    for (int i = 0; i < 4; i++)
    {
        char nx = "ACGT"[i];
        if (isOk(base + nx))
        {
            tmp += dfs(pos + 1, base.substr(1) + nx);
            tmp %= m;
        }
    }
    return cnt[pos][base] = tmp;
}

int main()
{
    cin >> n;
    cnt.resize(n + 1);
    cout << dfs(0, "***") << endl;

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forna(i,a,n) for(int i =a; i < n; i++)
#define fornd(i,a) for (int i = (a)-1; i >= 0; i--)
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);
#define all(x) x.begin(), x.end()
typedef long long int unsigned lliu;
typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
#define MAXN 100005

int main(){
	fastIO
	int n;
	cin>>n;
	vvi v(n, vi(3));
	forn(i, n)
		forn(j, 3)
			cin>>v[i][j];
	vvi mem(n, vi(3, -1));
	forn(i, 3){
		mem[n-1][i] = v[n-1][i];
	}
	for(int i=n-2; i>=0; i--){
		forn(j, 3){
			mem[i][j]=v[i][j] + max(mem[i+1][(j+1)%3], mem[i+1][(j+2)%3]);
		}
	}
	cout<<max(mem[0][0], max(mem[0][1], mem[0][2]))<<endl;;

	return 0;
}

Measured memory_bytes: 11264
a, b = map(int, input().split())
p, q = (a+1)//4, (b+1)//4
x, y = (a+1)%4, (b+1)%4
if abs(a-b) < 4:
    ans = a
    for i in range(a+1, b+1):
        ans ^= i
    print(ans)

else:
    if x == 0:
        ans = a

        if y == 1:
            ans ^= b
        elif y == 2:
            ans ^= b
            ans ^= (b-1)
        elif y == 3:
            ans ^= b
            ans ^= (b-1)
            ans ^= (b-2)
        elif y == 0:
            ans ^= 0

        print(ans)

    elif x == 1:
        ans = 0

        if y == 1:
            ans ^= b
        elif y == 2:
            ans ^= b
            ans ^= (b-1)
        elif y == 3:
            ans ^= b
            ans ^= (b-1)
            ans ^= (b-2)
        elif y == 0:
            ans ^= 0

        print(ans)

    elif x == 2:
        ans = a
        ans ^= (a+1)
        ans ^= (a+2)

        if y == 1:
            ans ^= b
        elif y == 2:
            ans ^= b
            ans ^= (b-1)
        elif y == 3:
            ans ^= b
            ans ^= (b-1)
            ans ^= (b-2)
        elif y == 0:
            ans ^= 0

        print(ans)

    elif x == 3:
        ans = a
        ans ^= (a+1)

        if y == 1:
            ans ^= b
        elif y == 2:
            ans ^= b
            ans ^= (b-1)
        elif y == 3:
            ans ^= b
            ans ^= (b-1)
            ans ^= (b-2)
        elif y == 0:
            ans ^= 0

        print(ans)

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

int main() {
  int n;
  cin >> n;
  int r = 0, xa = 0, bx = 0, ba = 0;
  for (; n > 0; n--) {
    string s;
    cin >> s;
    for (int i = 0; i + 1 < s.size(); i++) {
      r += s[i] == 'A' && s[i + 1] == 'B';
    }
    xa += s.back() == 'A';
    bx += s.front() == 'B';
    ba += s.back() == 'A' && s.front() == 'B';
  }
  cout << r + min(xa, bx) - (ba && xa == ba && bx == ba) << endl;
}


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 MOD = 2019;

int main() {
  string s;cin>>s;
  int n=s.size();
  int c[n];
  rep(i,n) c[i] = s[i]-'0';
  reverse(c, c+n);
  int cnt[MOD];rep(i,MOD)cnt[i]=0;
  cnt[0]=1;
  int tot=0;
  int dx=1;
  int ans=0;
  rep(i,n) {
    tot += c[i] * dx;
    tot %= MOD;
    dx = dx*10 % MOD;
    ans += cnt[tot];
    cnt[tot] ++;
  }
  cout<<ans;
  
  
}


Measured memory_bytes: 4460
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

typedef long long ll;

int main() {
    int n, k; std::cin >> n >> k; --k;
    std::vector<int> x(n);
    for (auto& it : x) std::cin >> it;
    ll answ = (ll)1e18L;
    for (int i = k; i < n; ++i) {
        ll temp = std::min(std::abs(x[i]), std::abs(x[i-k])) + std::abs(x[i]-x[i-k]);
        answ = std::min(answ, temp);
    }
    std::cout << answ;
    return 0;
}

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

int n,s[4];
double f[305][305][305];

int main()
{
	cin>>n;
	for(int i=1,x;i<=n&&cin>>x;i++)
		s[x]++;
	for(int k=0;k<=n;k++)
	for(int j=0;j<=n;j++)
	for(int i=0;i<=n;i++)
	{
		if(!i && !j && !k)
			continue;
		int m=i+j+k;
		if(i)
			f[i][j][k] += f[i-1][j][k]*i/m;
		if(j)
			f[i][j][k] += f[i+1][j-1][k]*j/m;
		if(k)
			f[i][j][k] += f[i][j+1][k-1]*k/m;
		f[i][j][k] += n*1.0/m;
	}
	printf("%.10lf",f[s[1]][s[2]][s[3]]);
	
	return 0;
}

Measured memory_bytes: 219392
#include <stdio.h>
#include <math.h>
int main(){
/*(^(^(^(^(^o^)^)^)^)^) &#9602;&#9605;&#9607;&#9608;&#9619;&#9618;&#9617;('ω')&#9617;&#9618;&#9619;&#9608;&#9607;&#9605;&#9602; */
int a,b,s=0,sum=0;
double av=0;
while(scanf("%d,%d",&a,&b)!=EOF){
sum+=a*b;
av+=b;
s++;
}
av/=s;
int aa;
if(av-floor(av)<0.5){
aa=floor(av);
}else{
aa=ceil(av);
}
printf("%d\n%d\n",sum,aa);
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) (x).begin (),(x).end()
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define si set<ll>
#define rep(i,a,b) for(unsigned ll i=a;i<b;i++)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MOD 1000000007LL
#define pi 3.14159265358979323846
ll binary_power(ll a, ll n) {
    if (n==0) return 1;
    ll k=binary_power(a,n/2);
    if (n%2==0) return (k*k)%MOD;
    else return (((k*k)%MOD)*a)%MOD;
}
bool isPrime(int num){
    bool flag=true;
    for(int i = 2; i*i <= num ; i++) {
       if(num % i == 0) {
          flag = false;
          break;
       }
    }
    return flag;
}

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

void solve()
{
    long double r; cin>>r;
    r = 2*pi*r;
    cout<<setprecision(10)<<r;
}

int main()
{
    SPEED;
    ll t = 1;

  // cin>>t;

    while(t--) solve();

   return 0;
}


Measured memory_bytes: 3804
import sys
input = sys.stdin.readline
N, X = map(int, input().split())
def solve(n, x):
  #print(n, x)
  if n == 0:
    return 0
  if x == 1: return n * 3
  m = x
  y = n - n // x * x
  if y == 0: return n // x * x * 3
  return solve(m, y) + n // x * x * 3
print(solve(max(N - X, X), min(N - X, X)))

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


void solve() {
    int i,j,k,l,r,x,y; string s;
    bool exit = false;
    int N;
    cin >> N;
    ll A[N];
    FOR(i,N){
        cin >> A[i];
    }
    ll ret = 0;
    FOR(i,N){
        ret += A[i]-1; 
    }
    cout<<ret<<endl;
    /*cin>>N;
    vector<ll> V;
    FOR(x,N+1) {
            FOR(y,N+1) {
                    ll ret=1;
                    FOR(i,x) ret*=2;
                    FOR(i,y) ret*=5;
                    V.push_back(ret);
            }
    }
    sort(ALL(V));
    FORR(v,V) cout<<v<<endl;*/
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi					3.14159265359
ll INF=1e18+10;
ll MOD=1000000007;

int main()
{
    int n;cin>>n;
    string s;cin>>s;
    ll ans=1;
    rep(i,1,n)
    {
        if(s[i]==s[i-1])
            continue;
        else
            ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 512
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)

#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
const int N=200005;
int n,m;
struct People{
    int l,r,id;
    friend bool operator < (People a,People b){
        return a.r>b.r;
    }
}a[N],b[N];
bool inq[N];
int cnt;
priority_queue<People> q;
bool cmpl(const People &a,const People &b){
    return a.l<b.l;
}
bool cmpr(const People &a,const People &b){
    return a.r>b.r;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i].l,&a[i].r);
    sort(a+1,a+1+n,cmpl);
    int nowl=0,nowr=m+1,last;
    for(int i=1;i<=n;i++){
        a[i].id=i;
        if(nowl+1<=a[i].l){
            nowl++;
            q.push(a[i]);
            inq[i]=true;
        }
        else if(!q.empty()){
            People best=q.top();
            if(a[i].r>best.r){
                q.pop();
                inq[best.id]=false;
                q.push(a[i]);
                inq[i]=true;
            }
        }
    }
    for(int i=1;i<=n;i++)
        if(!inq[i])
            b[++cnt]=a[i];
    sort(b+1,b+1+cnt,cmpr);
    for(int i=1;i<=cnt&&nowr-1!=nowl;i++)
        if(nowr-1>=b[i].r)
            nowr--;
    printf("%d\n",n-(nowl+(m-nowr+1)));
    return 0;
}

Measured memory_bytes: 7924
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;cin>>S;
  bool isok = S[0]=='A';
  int N=S.length();
  int idc=S.find("C");
  isok &= idc!=-1&&S.rfind("C")==idc&&2<=idc&&idc+2<=N;
  repeat(i,N){
    if(i!=0&&i!=idc){
      isok &= 'a'<=S[i]&&S[i]<='z';
    }
  }
  cout <<(isok? "AC":"WA")<< endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)

int main()
{
    int n,l;
    cin >> n >> l;
    // long ans = 1e10;
    int minv = l;
    int ans = 0;
    REP1(i,n-1){
        if(abs(minv) > abs(l+i)){
            ans += minv; 
            minv=l+i;
        }else{
            ans += l+i;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define REP(i,n) for (int i = 0; i < n; ++ i)
#define FOR(i,a,b) for (int i = a; i <= b; ++ i)
#define FORD(i,b,a) for (int i = b; i >= a; -- i)
#define debug(x) cerr << #x << ": " << x << "\n"
#define task ""
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> li;
typedef vector<int> vi;

const int N = 2e5 + 5;
int n, a[N], b[N], v[N], res;

int count(int v[], int l, int r) {
	//cerr << "count " << l << " " << r << "\n";
	//cerr <<  upper_bound(v, v+n, r) - upper_bound(v, v+n, l-1) << "\n";
	return upper_bound(v, v+n, r) - upper_bound(v, v+n, l-1);
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	//freopen(task".inp", "r", stdin);
	//freopen(task".out", "w", stdout);
	cin >> n;
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> b[i];	
	REP(i, 29) {
		//cerr << "bit " << i << "\n";
		REP(j, n) {
			v[j] = b[j] & ((1 << (i+1)) - 1);
			//cerr << v[j] << " ";
		}
		//cerr << "\n";
		sort(v, v + n);
		REP(j, n) {
			int tmp = a[j] & ((1 << (i+1)) - 1);
			//cerr << tmp << " ";
			if ((count(v, (1 << i) - tmp, (1 << i+1) - 1 - tmp) + count(v, (3 << i) - tmp, (3 << i+1) - 1 - tmp)) % 2) {
				res ^= (1 << i);
			}
		}
		//cerr << res << "\n";
	}
	cout << res;
}


Measured memory_bytes: 2560
import sys
 
stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))
 
 
def main():
    n = ni()
    A = nl()
    mod = 10 ** 9 + 7
    s = sum(A)
    q = sum([a ** 2 for a in A])
    ans = (((s * s) - q)) // 2
    print(int(ans % mod))
 
 
if __name__ == '__main__':
    main()

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

int main() {
  int n; cin >> n;
  string s; cin >> s;
  int a = 0, ans = 0;
  rep(i,s.size()) {
    if (s[i] == 'I') a++;
    else a--;
    ans = max(ans, a);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3556
import math
p = list(map(int, input().split()))
a = p[0]
b = p[1]
x = p[2]

if x <= (a**2)*b/2:
  print(math.degrees(math.atan( a*(b**2)/(2*x) )))
else:
  print(math.degrees(math.atan( (2*(a**2)*b-2*x)/(a**3) )))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <limits>


template<class T>
T cc(T t)
{
	return t * (t - 1) / 2;
}

int main()
{
	int N, M;
	std::cin >> N >> M;

	int ans = cc(N) + cc(M);;
	std::cout << ans;
}

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

int main(){
    double n;
    int digit;
    int count;
    bool flag = 0;
    int res = 0;

    cin >> n;
    while(n >= 10){
        digit  = fmod(n, 10);
        n = floor(n/10);
        if(digit != 9){
            flag = 1;
        }
        count += 1;
    }

    if(flag == 1){
        res = (n-1) + 9*count;
    }else{
        res = n + 9*count;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <cstdio>

int M, N, K;

int field[1001][1001][3];

int main(){
  
  scanf("%d%d%d", &M, &N ,&K);
  
  
  for(int i = 0; i <= M; i++){
    for(int j = 0; j < 3; j++){
      field[i][0][j] = 0;
    }
  }
  for(int i = 0; i <= N; i++){
    for(int j = 0; j < 3; j++){
      field[0][i][j] = 0;
    }
  }
  
  char aaaaaaaaaaaaaaaaaaaaa;
  scanf("%c", &aaaaaaaaaaaaaaaaaaaaa);
  
  for(int i = 1; i <= M; i++){
    for(int j = 1; j <= N; j++){
      char in;
      scanf("%c", &in);
      for(int k = 0; k < 3; k++){
        field[i][j][k] = field[i - 1][j][k] + field[i][j - 1][k] - field[i - 1][j - 1][k];
      }
      if(in == 'J'){
        field[i][j][0]++;
      }else if(in == 'O'){
        field[i][j][1]++;
      }else{
        field[i][j][2]++;
      }
    }
    char aaaaaaaaaaaaaaaaaaaaa;
    scanf("%c", &aaaaaaaaaaaaaaaaaaaaa);
  }
  
  
  for(int i = 0; i < K; i++){
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    for(int j = 0; j < 3; j++){
      int ret = field[c][d][j] - field[c][b - 1][j] - field[a - 1][d][j] + field[a - 1][b - 1][j];
      printf("%d", ret);
      if(j != 2){
        printf(" ");
      }
    }
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 12656
#include <stdio.h>

int main(void){
  int days[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};
  char youbi[7][100] = {"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
  int sum,m,d,i;
  while(1){
    sum = 0;
    scanf("%d %d",&m,&d);
    if (m == 0 || d == 0) break;
    for(i=0;i<m;i++){
      sum += days[i];
    }
    sum += d;
    printf("%s\n",youbi[sum%7]);
  }
  return 0;
}

Measured memory_bytes: 1012
#include <cstdio>
#include <cctype>
using namespace std;

int main(void){
    
    //変数：入力する各文字を「 C 」と置く
    char C;
    
    //繰り返し条件：改行があるまで繰り返す
    while(1){
        
        //入力：各文字を「 C 」を入力する
        scanf("%c", &C);
        
        //判定：アルファベットか判定 ちなみにそれ以外は記号や空白が確定!!!!!!!!
        if( isalpha(C) ){
            //判定：小文字か判定 ちなみにそれ以外は大文字が確定!!!!!
            if( islower(C) ) printf( "%c", toupper(C) );
            else printf( "%c", tolower(C) );
        }
        //記号や空白を表示
        else printf( "%c", C);
        
        //判定：改行があるか判定！！！
        if ( C == '\n') break;
    }
    
    return 0;
}


Measured memory_bytes: 2500
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int64_t x;
    cin >> x;
    cout << (x / 11) * 2 + (x % 11 > 0) + (x % 11 > 6) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n,k;
	cin >> n >> k;
	cout << n-k+1 << endl;
}

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

int main(){
  string N;
  cin >> N;
  char n = N.at(N.size()-1);
  if(n == '3') cout << "bon" << endl;
  else if(n == '0' || n == '1' || n == '6' || n == '8') cout << "pon" << endl;
  else cout << "hon" << endl;
  
  return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

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

    ll ans=n;

    for(int k=1; k<=40; ++k)
    {
        ll l=0, r=1000000;
        while(r-l>1)
        {
            ll m=(l+r)/2;

            bool ok=false;
            ll val=1;
            rep(i,k+1)
            {
                val*=m;
                if(val>=n)
                {
                    ok=true;
                    break;
                }
            }

            if(ok) r=m;
            else l=m;
        }

        rep(i,k+1)
        {
            ll val=1;

            bool ok=false;
            rep(j,i)
            {
                val*=r-1;
                if(val>=n)
                {
                    ok=true;
                    break;
                }
            }
            if(!ok)
            {
                rep(j,k+1-i)
                {
                    val*=r;
                    if(val>=n)
                    {
                        ok=true;
                        break;
                    }
                }
            }

            if(ok)
            {
                ll tmp = a*k + i*(r-1) + (k+1-i)*r;
                ans=min(ans,tmp);
            }
        }
    }

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


Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int a[10],ans,min=10;
    cin >>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    for(int i=0;i<5;i++){
        if(a[i]%10!=0){
        ans+=10*(a[i]/10+1);
            if(a[i]%10<min) min=a[i]%10;
        }
        else ans+=a[i];
    }
    cout<<ans-10+min;
    
}

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

int main(){
	int n,l;
	cin >> n >> l;
	string s[110];
	rep(i,n) cin >> s[i];
	string ans;
	sort(s,s+n);
	rep(i,n) ans += s[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
const double pi=acos(-1.0);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int main(void){
    long long n;
    cin>>n;
    vector<long long> a(n);
    rep(i,n){cin>>a[i];}
    sort(a.begin(), a.end());
    reverse(a.begin(),a.end());
    long long x=0,y=0,i=0;
    rep(i,n){
        if(i%2==0)x+=a[i];
        if(i%2==1)y+=a[i];
    }
    cout<<x-y<<endl;
}

Measured memory_bytes: 3556
// be my baby doll
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k;
int arr[200005],pre[200005],suff[200005];
map<pair<int,int>,int> mp,vis;
int solve(int curr,int state){
	if(curr==n) return 0;
	if(curr==n-1) return 1;
	if(vis[{curr,state}]==1) return mp[{curr,state}];
	vis[{curr,state}]=1;
	int res=1;
	// solve curr+1 k stages
	// curr+1 k-1 stages reaming or delete this
	if(state==0){
		int ans=solve(curr+1,state);
		res=max(ans,suff[curr]);
	}else{
		int ans=solve(curr+1,state);
		res=max(ans,suff[curr]);
		if(curr!=0 && curr!=n-1){
			// if curr is zero then it is not beneficial to delete it 
			ans=solve(curr+1,state-1);
			res=max(ans,pre[curr-1]+suff[curr+1]);
		}
	}
	mp[{curr,state}]=res;
	return res;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k,a,b; cin>>k>>a>>b;
    for(int i=a;i<=b;++i)
    	if(i%k==0){
    		cout<<"OK\n";
    		return 0;
    	}
    cout<<"NG\n";
    return 0;
}


// shakira your hips do not lie

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

int main() {
    int N;
    int Sum = 0;

    // input
    cin >> N;
    int A[N-1];
    for(int i=0; i<= N-2; i++){
        cin >> A[i];
    }

    int Buka[N];
    for(int i=0; i<= N-1; i++){
        Buka[i] = 0;
    }

    for(int i=0; i<= N-2; i++){
        Buka[A[i]-1] += 1;
    }

    for(int i=0; i<= N-1; i++){
        cout << Buka[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 5188
#include <stdio.h>

int count(int a) {
  int cnt;
  cnt = (a & 0x5555) + ((a>>1) & 0x5555);
  cnt = (cnt & 0x3333) + ((cnt >> 2) & 0x3333);
  cnt = (cnt & 0x0f0f) + ((cnt >> 4) & 0x0f0f);
  return (cnt & 0x00ff) + ((cnt >> 8) & 0x00ff);
}

int main() {
  int n, m, ans = 0, k, l, boo;
  scanf("%d %d", &n, &m);
  int s[m], p[m];
  for (size_t i = 0; i < m; i++) {
    scanf("%d", &k);
    s[i] = 0;
    for (size_t j = 0; j < k; j++) {
      scanf("%d", &l);
      s[i] += (1<<(l-1));
    }
  }
  for (size_t i = 0; i < m; i++) {
    scanf("%d", p+i);
  }
  for (size_t i = 0; i < (1<<n); i++) {
    boo = 1;
    for (size_t j = 0; j < m; j++) {
      if(count(s[j] & i) % 2 != p[j]){
        boo = 0;
        break;
      }
    }
    if (boo == 1) {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

int main() {
  map<char, char> table;
  table['A'] = 'T';
  table['T'] = 'A';
  table['C'] = 'G';
  table['G'] = 'C';
  char b;
  cin >> b;
  cout << table[b] << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ITP1_9-B
Discussion Solution Statistics Submit
 
String - Shuffle
Time Limit : 1 sec, Memory Limit : 65536 KB
?????£?????????

???????????¢????????????????????????????????? n ???????????????????±±????????£?????????????????????

1???????????£???????????§??????????????? h ???????????????????????¨???????????????????????????????????£????????????????±±??????????????????????????????

?????????????±±?????\???????????????????????????????????§?????????????????????

abcdeefab

?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

????????°???????????? h ??? 4 ??§?????£?????????????????¨????????????4?????? abcd ????????????????????? eefab ???????°??????£?????????????????§??\??????????????????????????????

eefababcd

???????????£???????????????????????°??????????????????

?????????????±±???????????????????????????????????¨ h ????????????????????????????????????????????????????????????????????????????????°?????????????????????????????????
Constraints

    ?????????????????????200????¶??????????
    ?????£?????????????????°???100????¶??????????

Input

?????°??????????????????????????\?????¨?????????????????????????????????????????????????????\????????¢?????§?????????????????????

????????????????????¨????????????
?????£??????????????° m
h1
h2
  .
  .
hm

????????????????????¨??????????????? "-" ?????¨?????\?????????????????¨????????????
Output

??????????????????????????????????????????????????????????????????????????????????????????????????????
Sample Input

aabc
3
1
2
1
vwxyz
2
3
4
-

Sample Output

aabc
xyzvw


=end
def shuffle(str, hl)
  if hl == [] then
    str
  else
    h = hl.shift
    len=str.length
    t = str.slice(h..(len-1)) + str.slice(0..(h-1))
    shuffle(t, hl)
  end
end

class Main
  def initialize()
    #fh = open("IPT1_9_B.txt")
    fh = STDIN
    while fh.gets
      break if $_=~ /^-$/
      str = $_.chomp
      n = fh.gets.chomp.to_i
      hl = []
      (1..n).each {|x|
        h = fh.gets.chomp.to_i
        hl.push(h) 
      }
      puts shuffle(str,hl)
    end
  end
end

if $0 == __FILE__ then
  Main.new
end

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

#define fi first
#define se second
#define endl '\n'
#define lc (rt<<1)
#define rc (rt<<1|1)
#define mp make_pair
#define pb push_back
#define lowbit(a) (a&(-a))
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define mst(a,v) memset(a,v,sizeof(a))
#define debug(x) cout<<#x": "<<x<<'\n';
#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

const int N=1000010;
const int mod=1e9+7;
const ld PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

template<typename T>inline void gmax(T &A,T B) {(A<B)&&(A=B);}
template<typename T>inline void gmin(T &A,T B) {(A>B)&&(A=B);}

template <class T>
inline bool re(T &ret)
{
    char c;
    int sgn;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    ret*=sgn;
    return 1;
}

int h[111111],dp[111111];

int main()
{
#ifdef local
    //freopen("in.txt", "r", stdin);
#endif
    IOS;
    int n;
    cin>>n;
    for(int i=1; i<=n; i++) cin>>h[i];
    dp[2]=abs(h[1]-h[2]);
    for(int i=3; i<=n; i++) dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

int n,m;
char c[300][300];
map<char,int>M;

int32_t main(){_
    //freopen("input","r",stdin);
    cin >> n >> m;
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= m;j++){
            cin >> c[i][j];
            M[c[i][j]]++;
        }
    }
    if(n % 2 == 0 && m % 2 == 0)
    {
        for(auto it : M) if(it.second % 4 != 0) rc("No");
        rc("Yes");
    }
    else if(n % 2 == 1 && m % 2 == 1)
    {
        bool b = 0;
        for(auto it : M)
        {
            if(it.second % 2 == 1)
            {
                if(b) rc("No");
                M[it.first]--;
                b = 1;
            }
        }
        if(!b) rc("No");
        int x = 0;
        int y = 0;
        for(auto it : M)
        {
            if(it.second % 4 != 0)
            {
                x++;
                M[it.first] -= 2;}
                                y += it.second / 4;
            
        }
        if(x == (n / 2) + (m / 2) && (y == (n*m - x * 2 - 1) / 4)) rc("Yes");
        if(x > (n / 2) + (m / 2)) rc("No");
        if(x < (n / 2) + (m / 2))
        {
            if(((n / 2) + (m / 2) - x) % 2 == 0)
            {
                y -= ((n / 2) + (m / 2) - x) / 2;
                                x = ((n / 2) + (m / 2));

                if(x == (n / 2) + (m / 2) && (y == (n*m - x * 2 - 1) / 4)) rc("Yes");
            }
        }
        rc("No");
    }
    if(n % 2 == 1) swap(n,m);
    bool b = 0;
        for(auto it : M)
        {
            if(it.second % 2 == 1)
            {
                rc("No");
            }
        }
        int x = 0;
        int y = 0;
        for(auto it : M)
        {
            if(it.second % 4 != 0)
            {
                x++;
                M[it.first] -= 2;
            }
                            y += it.second / 4;

        }
        if(x == (n / 2) && (y == (n*m - x * 2) / 4)) rc("Yes");
        if(x > (n / 2)) rc("No");
        if(x < (n / 2))
        {
            if(((n / 2) - x) % 2 == 0)
            {
                y -= ((n / 2) - x) / 2;
                x = n / 2;
                if(x == (n / 2) && (y == (n*m - x * 2) / 4)) rc("Yes");
            }
        }
        rc("No");
    }


Measured memory_bytes: 256
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

U = 55555
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
    if p*p > U:
        break
    if is_prime[p]:
        is_prime[p*p::p+p] = 0

primes = np.where(is_prime)[0]
primes = primes[primes%5 == 2]
N = ir()
answer = primes[:N]
print(*answer)


Measured memory_bytes: 13408
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, x, m;
	cin >> n >> x >> m;
	ll cur = x;
	map<int, int> vis;
	vis[cur] = 1;
	int lst = -1, rd = -1;
	repn(i, 2, min(n + 3, m + 3)){
		cur = sq(cur);
		cur %= m;
		if(vis[cur]){
			lst = cur;
			rd = i - 1;
			break;
		}
		if(!vis[cur]) vis[cur] = i;
	}
	if(rd == -1){
		//means we just sum it up - no cycle because n is too small
		cur = x;
		ll tot = 0LL;
		repn(i, 1, n + 1){
			if(i != 1) cur = sq(cur) % m;
			tot += cur;
		}
		cout << tot << endl;
		return 0;
	}
	ll sum = 0LL;
	cur = x;
	repn(i, 1, vis[lst]){
		if(i == 1) sum += x;
		else{
			cur = sq(cur) % m;
			sum += cur;
		}
	}
	ll cyc = 0LL;
	repn(j, vis[lst], rd + 1){
		if(j == 1) cyc += x;
		else{
			cur = sq(cur) % m;
			cyc += cur;
		}
	}
	ll rem = n - vis[lst] + 1;
	sum += cyc * (rem / (rd - vis[lst] + 1));
	rem %= (rd - vis[lst] + 1);
	rep(i, rem){
		cur = sq(cur) % m;
		sum += cur;
	}
	cout << sum << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 5940
N = gets.to_i
A = gets.split.map(&:to_i)

od = 0
ev = 0
ans = 0

A.each do |a|
  if a % 2 == 1
    od += 1
  else
    ev += 1
  end
end

pls = od / 2
od = od % 2
ev += pls

if od == 1
  puts 'NO'
else
  puts 'YES'
end


Measured memory_bytes: 8452
from itertools import accumulate

N,K = map(int, input().split())
mod = 10**9+7
sqt = int(N**0.5)
cnt = [N // i-N // (i+1) for i in range(1, N//sqt)] + [1]*sqt
x = cnt
for _ in range(K):
    x = [(i*j)%mod for i, j in zip(accumulate(reversed(x)), cnt)]
    

print(x[-1])

Measured memory_bytes: 10640
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>
#include <map>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;

typedef queue<ll> ql;
typedef queue<int> qi;

template <class T>
void printv(vector<T> vc)
{
    for (auto e : vc)
        cout << e << " ";
    cout << endl;
}

template <class T>
void printvv(vector<T> vvc)
{
    for (auto vc : vvc)
    {
        for (auto e : vc)
            cout << e << " ";
        cout << endl;
    }
}

template <class T>
void printvp(vector<pair<T, T> > vp)
{
    for (auto pT : vp)
        cout << pT.first << " " << pT.second << endl;
}

int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    vs v = {"dream", "dreamer", "erase", "eraser"};
    for (int i = 0; i < v.size(); ++i) {
        reverse(v[i].begin(), v[i].end());
    }

    auto a = true;
    for (int i = 0; i < s.size();) {
        auto b = false;
        for (int j = 0; j < v.size(); ++j) {
            const auto target = v[j];
            if (s.substr(i, target.size()) == target) {
                i += target.size();
                b = true;
            }
        }
        if (!b) {
            a = false;
            break;
        }
    }

    cout << (a ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; cin >> N;
	V<int> A(N),B(N);
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];
	rep(i,N) if(A[i] > B[i]){
		cout << -1 << endl;
		return 0;
	}
	using P = pair<int,int>;
	priority_queue<P> q;
	rep(i,N) q.push(P(B[i],i));
	ll ans = 0;
	while(!q.empty()){
		int i = q.top().sc; q.pop();
		int d = B[(i+1)%N]+B[(i+N-1)%N];
		int t = (B[i]-A[i])/d;
		if(t == 0) continue;
		B[i] -= t*d;
		ans += t;
		if(B[i] != A[i]) q.push(P(B[i],i));
	}
	rep(i,N) if(A[i] != B[i]){
		cout << -1 << endl;
		return 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3956
#include <stdio.h>

int main() {
	int X, Y, Z;
	
	scanf("%d %d %d", &X, &Y, &Z);
	
	int num = 0;
	for(int i = X; i <= Y; i++){
		if(i % Z == 0) {
			num++;
		}
	} 
	printf("%d\n", num);
	return 0;
}

Measured memory_bytes: 1720
n = int(input())
li_a = list(map(int, input().split()))
m = 1000
a = 0
for i in range(n-1):
    if li_a[i] < li_a[i+1]:
        a = m//li_a[i]
        m -= a*li_a[i]
        m += a*li_a[i+1]
    else:
        continue
print(m)

Measured memory_bytes: 61832
N,Q=map(int,input().split())
s=["x"]+list(input())+["x"]
#print(s)
L=[]
for i in range(Q):
    t=list(input().split())
    L.append(t)
#print(L)
h=N
l=1
LEFT=-10
RIGHT=-10
while abs(h-l)>2:
    Mid=(h+l)//2
    P=Mid
    for i in range(Q):
        if s[P]==L[i][0]:
            if L[i][1]=="L":
                P-=1
            else:
                P+=1
                
    if P==0:
        l=Mid
    else:
        h=Mid
#print(l,h)
for j in range(4):
    M=l-1+j
    P=M
    for i in range(Q):
        if s[P]==L[i][0]:
            #print("S",j,P,i)
            if L[i][1]=="R":
                P+=1
            else:
                P-=1
    #print("A",M,P)
    if P!=0:
        LEFT=l-1+j
        break

h=N
l=1

while abs(h-l)>2:
    Mid=(h+l)//2
    P=Mid
    for i in range(Q):
        if s[P]==L[i][0]:
            if L[i][1]=="L":
                P-=1
            else:
                P+=1
                
    if P==N+1:
        h=Mid
    else:
        l=Mid
for j in range(4):
    M=h+1-j
    P=M
    for i in range(Q):
        if s[P]==L[i][0]:
            if L[i][1]=="L":
                P-=1
            else:
                P+=1
    if P!=N+1:
        RIGHT=h+1-j
        break
if LEFT==-10 or RIGHT==-10:
    print(0)
else:
    print(max(0,RIGHT - LEFT +1))
#print(RIGHT,LEFT)

Measured memory_bytes: 97840
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  ll S = 0;
  rep(i, N) {
    S += A[i];
  }
  // For Debug
  // cout << "sum: " << S << endl;

  set<ll> gcds;
  for (ll i = 2; i <= sqrt(S); ++i) { // i is the divisor
    if ((S % i) == 0) {
      gcds.insert(i);
      gcds.insert(S / i);
    }
  }
  gcds.insert(S);
  // For Debug
  // for (auto x : gcds) {
  //   cout << x << " ";
  // }
  // cout << endl;

  ll ans = 0;

  for (auto it = gcds.rbegin(); it != gcds.rend(); ++it) { // Try x in decreasing order.
    ll x = *it;

    // a[i]: (A[i] % x) = d (-d). increasing order.
    // b[i]: x - a[i]   = x-d (+ x-d). decreasing order.
    vector<ll> a(N);
    rep(i, N) {
      a[i] = A[i] % x;
    }
    sort(all(a));
    vector<ll> b(N);
    rep(i, N) {
      b[i] = x - (a[i]);
    }

    // For Debug
    // cout << "a: ";
    // rep(i, N) {
    //   cout << a[i] << " ";
    // }
    // cout << endl;
    // cout << "b: ";
    // rep(i, N) {
    //   cout << b[i] << " ";
    // }
    // cout << endl;

    // sumA[i]: summention of a from 0 to i.
    // sumB[i]: summention of b from i to N-1.
    vector<ll> sumA = a;
    vector<ll> sumB = b;
    for (int i = 0; i < N-1; ++i) {
      sumA[i+1] += sumA[i];
    }
    for (int i = N-1; i > 0; --i) {
      sumB[i-1] += sumB[i];
    }

    // Find the k in which sumA[k] = sumB[k+1]
    int k;
    for (k = 0; k < N-1; ++k) {
      if (sumA[k] == sumB[k+1]) { break; }
    }
    int summed = 0;
    for (int i = 0; i <= k; ++i) {
      summed += a[i];
    }
    if (summed <= K) { // OK.
      ans = x;
      break;
    }
  }

  if (ans > 0) {
    cout << ans << endl;
  } else {
    cout << 1 << endl;
  }
}


Measured memory_bytes: 384
while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break

    count = 0
    start = n if n < x else x
    for a in range(start, 0, -1):
        if a >= x:
            continue
        for b in range(a - 1, 0, -1):
            if sum([a,b]) >= x:
                continue
            for c in range(b - 1, 0, -1):
                if sum([a,b,c]) == x:
                    count += 1
    print(count)

Measured memory_bytes: 6720